FIXED: bug of only working for first coupon on an order
-
We discovered that this coupon only works if the Free Trial coupon is the first coupon applied to an order. However we have clients that auto-apply some coupons like member discount and such so our free trial coupon is applied second which causes it not to work.
We’ve patched the plugin but can you please add this to the official plugin.
Edit file: wp-content/plugins/extended-trial-coupon-for-wc-subscription/includes/Trial_Coupon_Actions.php
Replace this:public function before_caculate_cart_total( $cart ) { if ( $cart->get_applied_coupons() ) { // Get Coupon id $coupon_id = $cart->get_applied_coupons()[0]; $coupon = new \WC_Coupon( $coupon_id ); $coupon_trial_length = $coupon->get_meta('_wcs_trial_coupon_length'); $coupon_trial_period = $coupon->get_meta('_wcs_trial_coupon_period'); // Check if the coupon apply if ( $coupon_trial_length > 0 ) { foreach( $cart->cart_contents as $cart_item_id=>$cart_item ) { if ( is_a($cart_item['data'], 'WC_Product_Subscription' ) || is_a( $cart_item['data'], 'WC_Product_Subscription_Variation' ) ) { $cart_item['data']->update_meta_data( '_subscription_trial_length', $coupon_trial_length, true ); $cart_item['data']->update_meta_data( '_subscription_trial_period', $coupon_trial_period, true ); } } } } }
with this:
public function before_caculate_cart_total( $cart ) { if ( $cart->get_applied_coupons() ) { // Get Coupons $coupons = WC()->cart->get_applied_coupons(); // Loop through coupons. foreach ( $coupons as $coupon_id ) { $coupon = new \WC_Coupon( $coupon_id ); $coupon_trial_length = $coupon->get_meta('_wcs_trial_coupon_length'); $coupon_trial_period = $coupon->get_meta('_wcs_trial_coupon_period'); // Check if the coupon apply if ( $coupon_trial_length > 0 ) { foreach( $cart->cart_contents as $cart_item_id=>$cart_item ) { if ( is_a($cart_item['data'], 'WC_Product_Subscription' ) || is_a( $cart_item['data'], 'WC_Product_Subscription_Variation' ) ) { $cart_item['data']->update_meta_data( '_subscription_trial_length', $coupon_trial_length, true ); $cart_item['data']->update_meta_data( '_subscription_trial_period', $coupon_trial_period, true ); } } } } } }
- The topic ‘FIXED: bug of only working for first coupon on an order’ is closed to new replies.