Skip to content

Commit 53b5d81

Browse files
committed
Adding course capacity check on the checkout page.
1 parent d017ac9 commit 53b5d81

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

includes/shortcodes/class.llms.shortcode.checkout.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,35 @@ private static function checkout( $atts ) {
106106
llms_get_login_form( sprintf( __( 'Already have an account? <a href="%s">Click here to login</a>', 'lifterlms' ), '#llms-show-login' ), $atts['plan']->get_checkout_url() );
107107
}
108108

109+
if ( isset( $atts['product'] ) && 'course' === $atts['product']->get( 'type' ) && ( $course = new LLMS_Course( $atts['product']->post ) ) && ! $course->has_capacity() ) {
110+
/**
111+
* Filter the displaying of the checkout form notice for already enrolled in the product being purchased.
112+
*
113+
* @param bool $display_notice Whether or not displaying the checkout form notice for already enrolled students in the product being purchased.
114+
* @param LLMS_Access_Plan $plan The access plan.
115+
*
116+
* @since 4.2.0
117+
*/
118+
if ( apply_filters( 'llms_display_checkout_form_course_capacity_notice', true, $atts['plan'] ) ) {
119+
llms_print_notice(
120+
$course->get( 'capacity_message' ),
121+
'error'
122+
);
123+
}
124+
125+
/**
126+
* Filter to block checkout when the course capacity has been reached. Defaults to true.
127+
*
128+
* @param bool $block_checkout Whether or not blocking the checkout form when a course is at capacity.
129+
* @param LLMS_Access_Plan $plan The access plan.
130+
*
131+
* @since [version]
132+
*/
133+
if ( apply_filters( 'llms_checkout_block_course_capacity_checkout', true, $atts['plan'] ) ) {
134+
return;
135+
}
136+
}
137+
109138
llms_get_template( 'checkout/form-checkout.php', $atts );
110139
}
111140

0 commit comments

Comments
 (0)