Created
August 12, 2020 07:30
-
-
Save kreamweb/7e0f4990ca666d4c49f1dd3293dc99b5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'woocommerce_applied_coupon', 'change_subscription_next_payment_due_date' ); | |
add_action( 'woocommerce_removed_coupon', 'change_subscription_next_payment_due_date_on_remove_coupon' ); | |
function change_subscription_next_payment_due_date( $coupon_code ) { | |
if ( 'bundle' === strtolower( $coupon_code ) ) { | |
change_next_billing_date( 90 ); | |
} | |
} | |
function change_subscription_next_payment_due_date_on_remove_coupon( $coupon_code ){ | |
if ( 'bundle' === strtolower( $coupon_code ) ) { | |
change_next_billing_date( 30 ); | |
} | |
} | |
function change_next_billing_date( $days ){ | |
if ( did_action( 'wp_loaded' ) && isset( WC()->cart ) ) { | |
$contents = WC()->cart->get_cart(); | |
if ( ! empty( $contents ) ) { | |
foreach ( $contents as $item_key => $item ) { | |
$product = $item['data']; | |
if ( ywsbs_is_subscription_product( $product ) && $product->get_id() === 12451 ) { | |
$subscription_info = $item['ywsbs-subscription-info']; | |
if ( $subscription_info ) { | |
$subscription_info['next_payment_due_date'] = time() + $days * DAY_IN_SECONDS; | |
WC()->cart->cart_contents[ $item_key ]['ywsbs-subscription-info'] = $subscription_info; | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment