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 );
}
}
}
}
}
}
]]>
I noticed the following error:
03-05-2023 @ 23:19:25 – scheduled action xxxx (subscription trial end) failed to finish processing due to the following exception: Scheduled action for woocommerce_scheduled_subscription_trial_end will not be executed as no callbacks are registered.
03-05-2023 @ 23:19:25 – action args: subscription_id: xxxx
Can this be related to this plugin?
]]>