diff --git a/admin/class-openedx-commerce-admin.php b/admin/class-openedx-commerce-admin.php
index 80dc75b..35046b2 100644
--- a/admin/class-openedx-commerce-admin.php
+++ b/admin/class-openedx-commerce-admin.php
@@ -498,11 +498,23 @@ public function select_course_items( $items, $is_refunded = false ) {
*/
public function items_enrollment_request( $courses, $order_id, $billing_email, $request_type ) {
+ $force_enrollment = get_option( 'openedx-enrollment-force', false );
+ $allow_non_existing = get_option( 'openedx-enrollment-allowed', false );
+
+ if ( $force_enrollment && $allow_non_existing ) {
+ $action = 'openedx_enrollment_allowed_force';
+ } elseif ( $force_enrollment ) {
+ $action = 'openedx_enrollment_force';
+ } elseif ( $allow_non_existing ) {
+ $action = 'openedx_enrollment_allowed';
+ } else {
+ $action = 'enrollment_process';
+ }
+
foreach ( $courses as $item_id => $item ) {
$course_id = get_post_meta( $item['course_item']->get_product_id(), '_course_id', true );
$course_mode = get_post_meta( $item['course_item']->get_product_id(), '_mode', true );
- $action = 'enrollment_process';
$enrollment_arr = array(
'openedx_enrollment_course_id' => $course_id,
diff --git a/admin/views/class-openedx-commerce-settings.php b/admin/views/class-openedx-commerce-settings.php
index b9d8713..3948983 100644
--- a/admin/views/class-openedx-commerce-settings.php
+++ b/admin/views/class-openedx-commerce-settings.php
@@ -125,6 +125,22 @@ public function openedx_settings_init() {
'openedx-settings-section'
);
+ add_settings_field(
+ 'openedx-enrollment-force',
+ 'Force Enrollment',
+ array( $this, 'openedx_enrollment_force_callback' ),
+ 'openedx-settings',
+ 'openedx-settings-section'
+ );
+
+ add_settings_field(
+ 'openedx-enrollment-allowed',
+ 'Allow Non-Existing Users',
+ array( $this, 'openedx_enrollment_allowed_callback' ),
+ 'openedx-settings',
+ 'openedx-settings-section'
+ );
+
register_setting(
'openedx-settings-group',
'openedx-domain',
@@ -149,6 +165,36 @@ public function openedx_settings_init() {
'sanitize_text_field'
);
+ register_setting(
+ 'openedx-settings-group',
+ 'openedx-enrollment-force',
+ array(
+ 'type' => 'boolean',
+ 'sanitize_callback' => 'rest_sanitize_boolean',
+ 'default' => false,
+ )
+ );
+
+ register_setting(
+ 'openedx-settings-group',
+ 'openedx-enrollment-allowed',
+ array(
+ 'type' => 'boolean',
+ 'sanitize_callback' => 'rest_sanitize_boolean',
+ 'default' => false,
+ )
+ );
+
+ register_setting(
+ 'openedx-settings-group',
+ 'openedx-enrollment-allowed',
+ array(
+ 'type' => 'boolean',
+ 'sanitize_callback' => 'rest_sanitize_boolean',
+ 'default' => false,
+ )
+ );
+
if ( ! isset( $_POST['openedx_commerce_new_token_nonce'] ) ||
! wp_verify_nonce( sanitize_key( wp_unslash( $_POST['openedx_commerce_new_token_nonce'] ) ), 'openedx_commerce_token' )
) {
@@ -324,5 +370,35 @@ public function openedx_settings_section_callback() {
'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 Create an Open edX Application for the Plugin Settings in the documentation.'
);
}
+
+ /**
+ * Output the enrollment force settings field.
+ *
+ * Retrieves the saved enrollment force value and outputs a checkbox input field and description text.
+ *
+ * @return void
+ */
+ public function openedx_enrollment_force_callback() {
+ $force_enrollment = get_option('openedx-enrollment-force', false);
+ ?>
+ >
+
+
+ >
+
+