Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Tags: openedx, open edx, ecommerce, lms, courses
Requires at least: 6.3
Tested up to: 6.8
Requires PHP: 8.0
Stable tag: 2.0.7
Stable tag: 2.1.0
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down
14 changes: 13 additions & 1 deletion admin/class-openedx-commerce-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
66 changes: 66 additions & 0 deletions admin/views/class-openedx-commerce-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,22 @@ public function openedx_settings_init() {
'openedx-settings-section'
);

add_settings_field(
'openedx-enrollment-force',
__( 'Force Enrollment', 'openedx-commerce' ),
array( $this, 'openedx_enrollment_force_callback' ),
'openedx-settings',
'openedx-settings-section'
);

add_settings_field(
'openedx-enrollment-allowed',
__( 'Allow Non-Existing Users', 'openedx-commerce' ),
array( $this, 'openedx_enrollment_allowed_callback' ),
'openedx-settings',
'openedx-settings-section'
);

register_setting(
'openedx-settings-group',
'openedx-domain',
Expand All @@ -149,6 +165,26 @@ 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,
)
);

if ( ! isset( $_POST['openedx_commerce_new_token_nonce'] ) ||
! wp_verify_nonce( sanitize_key( wp_unslash( $_POST['openedx_commerce_new_token_nonce'] ) ), 'openedx_commerce_token' )
) {
Expand Down Expand Up @@ -324,5 +360,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 <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.'
);
}

/**
* 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 );
?>
<input type="checkbox" id="openedx-enrollment-force" name="openedx-enrollment-force" value="1" <?php checked( 1, $force_enrollment, true ); ?>>
<label for="openedx-enrollment-force"><?php esc_html_e( 'Use the "force" flag. Disregard the course\'s enrollment end dates.', 'openedx-commerce' ); ?></label>
<?php
}

/**
* Output the enrollment allowed settings field.
*
* Retrieves the saved enrollment allowed value and outputs a checkbox input field and description text.
*
* @return void
*/
public function openedx_enrollment_allowed_callback() {
$allow_non_existing = get_option( 'openedx-enrollment-allowed', false );
?>
<input type="checkbox" id="openedx-enrollment-allowed" name="openedx-enrollment-allowed" value="1" <?php checked( 1, $allow_non_existing, true ); ?>>
<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>
<?php
}
}

4 changes: 2 additions & 2 deletions openedx-commerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Open edX Commerce
* Plugin URI: https://github.com/openedx/openedx-wordpress-ecommerce
* Description: Easily connect your WooCommerce store to Open edX.
* Version: 2.0.7
* Version: 2.1.0
* Author: Open edX Community
* Author URI: https://github.com/openedx/openedx-wordpress-ecommerce
* License: GPL-2.0+
Expand Down Expand Up @@ -32,7 +32,7 @@
* Start at version 1.0.0 and use SemVer - https://semver.org
* Rename this for your plugin and update it as you release new versions.
*/
define( 'OPENEDX_COMMERCE_VERSION', '2.0.7' );
define( 'OPENEDX_COMMERCE_VERSION', '2.1.0' );

/**
* The code that runs during plugin activation.
Expand Down