Skip to content

Commit 80e1e75

Browse files
feat: Save enrollment action preferences (#111)
* feat: saving "forced" enrollment action * fix: linting and fixing QA reports fix: linting the settings file fix: linting * fix: bumping to v2.1.0 * chore: adding changelog --------- Co-authored-by: Felipe Montoya <felipe.montoya@edunext.co>
1 parent fc1aa2a commit 80e1e75

5 files changed

Lines changed: 105 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
1+
## v2.1.0 - 2025-08-05
2+
3+
### [2.1.0](https://github.com/openedx/openedx-wordpress-ecommerce/compare/v2.0.7...v2.1.0) (2025-08-05)
4+
5+
#### Features
6+
7+
* feat: add publish to wordpress svn action (#103)
8+
* feat: Save enrollment action preferences (#111)
9+
10+
#### Bug Fixes
11+
12+
* fix: add parent property to avoid dynamic property warning (#109)
13+
* fix: updating i18n management (2025 best practices) (#114)
14+
15+
### Documentation
16+
17+
* docs: add automatic installation info and change github docs links to rtd docs (#108)
18+
19+
### Maintenance
20+
21+
* chore: actions auto updates.
22+
* chore: Tag this repo as part of named releases (#110)
23+
124
## v2.0.7 - 2024-11-05
225

326
### [2.0.7](https://github.com/openedx/openedx-wordpress-ecommerce/compare/v2.0.6...v2.0.7) (2024-11-05)

README.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Tags: openedx, open edx, ecommerce, lms, courses
44
Requires at least: 6.3
55
Tested up to: 6.8
66
Requires PHP: 8.0
7-
Stable tag: 2.0.7
7+
Stable tag: 2.1.0
88
License: GPLv2 or later
99
License URI: http://www.gnu.org/licenses/gpl-2.0.html
1010

admin/class-openedx-commerce-admin.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,11 +498,23 @@ public function select_course_items( $items, $is_refunded = false ) {
498498
*/
499499
public function items_enrollment_request( $courses, $order_id, $billing_email, $request_type ) {
500500

501+
$force_enrollment = get_option( 'openedx-enrollment-force', false );
502+
$allow_non_existing = get_option( 'openedx-enrollment-allowed', false );
503+
504+
if ( $force_enrollment && $allow_non_existing ) {
505+
$action = 'openedx_enrollment_allowed_force';
506+
} elseif ( $force_enrollment ) {
507+
$action = 'openedx_enrollment_force';
508+
} elseif ( $allow_non_existing ) {
509+
$action = 'openedx_enrollment_allowed';
510+
} else {
511+
$action = 'enrollment_process';
512+
}
513+
501514
foreach ( $courses as $item_id => $item ) {
502515

503516
$course_id = get_post_meta( $item['course_item']->get_product_id(), '_course_id', true );
504517
$course_mode = get_post_meta( $item['course_item']->get_product_id(), '_mode', true );
505-
$action = 'enrollment_process';
506518

507519
$enrollment_arr = array(
508520
'openedx_enrollment_course_id' => $course_id,

admin/views/class-openedx-commerce-settings.php

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,22 @@ public function openedx_settings_init() {
125125
'openedx-settings-section'
126126
);
127127

128+
add_settings_field(
129+
'openedx-enrollment-force',
130+
__( 'Force Enrollment', 'openedx-commerce' ),
131+
array( $this, 'openedx_enrollment_force_callback' ),
132+
'openedx-settings',
133+
'openedx-settings-section'
134+
);
135+
136+
add_settings_field(
137+
'openedx-enrollment-allowed',
138+
__( 'Allow Non-Existing Users', 'openedx-commerce' ),
139+
array( $this, 'openedx_enrollment_allowed_callback' ),
140+
'openedx-settings',
141+
'openedx-settings-section'
142+
);
143+
128144
register_setting(
129145
'openedx-settings-group',
130146
'openedx-domain',
@@ -149,6 +165,26 @@ public function openedx_settings_init() {
149165
'sanitize_text_field'
150166
);
151167

168+
register_setting(
169+
'openedx-settings-group',
170+
'openedx-enrollment-force',
171+
array(
172+
'type' => 'boolean',
173+
'sanitize_callback' => 'rest_sanitize_boolean',
174+
'default' => false,
175+
)
176+
);
177+
178+
register_setting(
179+
'openedx-settings-group',
180+
'openedx-enrollment-allowed',
181+
array(
182+
'type' => 'boolean',
183+
'sanitize_callback' => 'rest_sanitize_boolean',
184+
'default' => false,
185+
)
186+
);
187+
152188
if ( ! isset( $_POST['openedx_commerce_new_token_nonce'] ) ||
153189
! wp_verify_nonce( sanitize_key( wp_unslash( $_POST['openedx_commerce_new_token_nonce'] ) ), 'openedx_commerce_token' )
154190
) {
@@ -324,5 +360,35 @@ public function openedx_settings_section_callback() {
324360
'Configuring the necessary parameters here to establish the connection between this plugin and your Open edX platform. For more information, you can visit the how-to <a href="https://docs.openedx.org/projects/wordpress-ecommerce-plugin/en/latest/how-tos/create_an_openedx_app.html">Create an Open edX Application for the Plugin Settings</a> in the documentation.'
325361
);
326362
}
363+
364+
/**
365+
* Output the enrollment force settings field.
366+
*
367+
* Retrieves the saved enrollment force value and outputs a checkbox input field and description text.
368+
*
369+
* @return void
370+
*/
371+
public function openedx_enrollment_force_callback() {
372+
$force_enrollment = get_option( 'openedx-enrollment-force', false );
373+
?>
374+
<input type="checkbox" id="openedx-enrollment-force" name="openedx-enrollment-force" value="1" <?php checked( 1, $force_enrollment, true ); ?>>
375+
<label for="openedx-enrollment-force"><?php esc_html_e( 'Use the "force" flag. Disregard the course\'s enrollment end dates.', 'openedx-commerce' ); ?></label>
376+
<?php
377+
}
378+
379+
/**
380+
* Output the enrollment allowed settings field.
381+
*
382+
* Retrieves the saved enrollment allowed value and outputs a checkbox input field and description text.
383+
*
384+
* @return void
385+
*/
386+
public function openedx_enrollment_allowed_callback() {
387+
$allow_non_existing = get_option( 'openedx-enrollment-allowed', false );
388+
?>
389+
<input type="checkbox" id="openedx-enrollment-allowed" name="openedx-enrollment-allowed" value="1" <?php checked( 1, $allow_non_existing, true ); ?>>
390+
<label for="openedx-enrollment-allowed"><?php esc_html_e( 'Create course enrollment allowed if the user doesn\'t exist in the Open edX platform.', 'openedx-commerce' ); ?></label>
391+
<?php
392+
}
327393
}
328394

openedx-commerce.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Plugin Name: Open edX Commerce
44
* Plugin URI: https://github.com/openedx/openedx-wordpress-ecommerce
55
* Description: Easily connect your WooCommerce store to Open edX.
6-
* Version: 2.0.7
6+
* Version: 2.1.0
77
* Author: Open edX Community
88
* Author URI: https://github.com/openedx/openedx-wordpress-ecommerce
99
* License: GPL-2.0+
@@ -32,7 +32,7 @@
3232
* Start at version 1.0.0 and use SemVer - https://semver.org
3333
* Rename this for your plugin and update it as you release new versions.
3434
*/
35-
define( 'OPENEDX_COMMERCE_VERSION', '2.0.7' );
35+
define( 'OPENEDX_COMMERCE_VERSION', '2.1.0' );
3636

3737
/**
3838
* The code that runs during plugin activation.

0 commit comments

Comments
 (0)