From 8dca20f6c00c84c375b04a8b05029ed910316a75 Mon Sep 17 00:00:00 2001 From: maximilianoRicoTabo Date: Wed, 27 Nov 2024 13:20:06 -0300 Subject: [PATCH] [BUGFIXING] #39 Discount code ignored * Bail if discount code is applied via URL. * Remove payment plan card if discount code is applied via AJAX. --- pmpro-payment-plans.php | 77 +++++++++++++++++++++++++++++------------ 1 file changed, 55 insertions(+), 22 deletions(-) diff --git a/pmpro-payment-plans.php b/pmpro-payment-plans.php index d28453e..d2f96b3 100644 --- a/pmpro-payment-plans.php +++ b/pmpro-payment-plans.php @@ -427,29 +427,41 @@ function pmpropp_render_payment_plans_checkout() { } } - if ( ! empty( $level->id ) ) { - - $plans = pmpropp_return_payment_plans( intval( $level->id ) ); - - if ( ! empty( $plans ) ) { - ?> -
-
-
- -

-
-
-
- -
-
+ //Bail if empty level. + if ( empty( $level->id ) ) { + return; + } + + + $plans = pmpropp_return_payment_plans( intval( $level->id ) ); + + //Bail if no plans. + if ( empty( $plans ) ) { + return; + } + + //Bail if discount code is being used. + if ( isset( $level->code_id ) ) { + return; + } + + ?> +
+
+
+ +

+
+
+
+
-
- +
+
+ id, 'checkout_vars' ); } -add_action( 'pmpro_after_checkout', 'pmpropp_merge_checkout_after_checkout', 1, 2 ); \ No newline at end of file +add_action( 'pmpro_after_checkout', 'pmpropp_merge_checkout_after_checkout', 1, 2 ); + +/** + * Remove payment plans when a discount code is applied. + * + * @param string $discount_code The discount code. + * @param int $discount_code_id The discount code ID. + * @param int $level_id The level ID. + * @param object $code_level The level object. + * @return void + * @since TBD + * + */ +function pmpropp_remove_payment_plans_when_discount_code_applied( $discount_code, $discount_code_id, $level_id, + $code_level ) { + // If a valid discount code is applied, remove payment plans. + if ( ! empty( $code_level ) ) { + // Remove the payment plans from the checkout page. + echo "jQuery( '#pmpropp_select_payment_plan' ).remove();"; + } +} +add_action( 'pmpro_applydiscountcode_return_js', 'pmpropp_remove_payment_plans_when_discount_code_applied', 10, 4 ); \ No newline at end of file