diff --git a/.changelogs/additional-checks-course-enrollment-cap.yml b/.changelogs/additional-checks-course-enrollment-cap.yml new file mode 100644 index 0000000000..25d6959d9c --- /dev/null +++ b/.changelogs/additional-checks-course-enrollment-cap.yml @@ -0,0 +1,5 @@ +significance: patch +type: changed +links: + - "#3086" +entry: Add additional check for course capacity on the checkout page. diff --git a/includes/shortcodes/class.llms.shortcode.checkout.php b/includes/shortcodes/class.llms.shortcode.checkout.php index 5bf054355f..a2cf0f5757 100644 --- a/includes/shortcodes/class.llms.shortcode.checkout.php +++ b/includes/shortcodes/class.llms.shortcode.checkout.php @@ -106,6 +106,35 @@ private static function checkout( $atts ) { llms_get_login_form( sprintf( __( 'Already have an account? Click here to login', 'lifterlms' ), '#llms-show-login' ), $atts['plan']->get_checkout_url() ); } + if ( isset( $atts['product'] ) && 'course' === $atts['product']->get( 'type' ) && ( $course = new LLMS_Course( $atts['product']->post ) ) && ! $course->has_capacity() ) { + /** + * Filter the displaying of the checkout form notice for already enrolled in the product being purchased. + * + * @param bool $display_notice Whether or not displaying the checkout form notice for already enrolled students in the product being purchased. + * @param LLMS_Access_Plan $plan The access plan. + * + * @since 4.2.0 + */ + if ( apply_filters( 'llms_display_checkout_form_course_capacity_notice', true, $atts['plan'] ) ) { + llms_print_notice( + $course->get( 'capacity_message' ), + 'error' + ); + } + + /** + * Filter to block checkout when the course capacity has been reached. Defaults to true. + * + * @param bool $block_checkout Whether or not blocking the checkout form when a course is at capacity. + * @param LLMS_Access_Plan $plan The access plan. + * + * @since [version] + */ + if ( apply_filters( 'llms_checkout_block_course_capacity_checkout', true, $atts['plan'] ) ) { + return; + } + } + llms_get_template( 'checkout/form-checkout.php', $atts ); }