Skip to content

Instantly share code, notes, and snippets.

@kreamweb
Created August 12, 2020 07:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kreamweb/7e0f4990ca666d4c49f1dd3293dc99b5 to your computer and use it in GitHub Desktop.
Save kreamweb/7e0f4990ca666d4c49f1dd3293dc99b5 to your computer and use it in GitHub Desktop.
<?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