Last active
November 17, 2021 15:18
-
-
Save jrick1229/1faa7e907216aa32e8dc24d37cc6d4a4 to your computer and use it in GitHub Desktop.
If an order is placed On Hold, change/keep the subscription's status as Active.
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 | |
/* | |
* If an order is created and placed On Hold, keep the subscription Active | |
* If an order is changed to On Hold, change the subscription status to Active | |
* | |
* wcs_order_contains_subscription( $order, 'any' ) | any / parent / renewal / switch | |
*/ | |
add_action( 'woocommerce_order_status_changed', 'wcs_sub_active_order_onhold', 10, 4 ); | |
function wcs_sub_active_order_onhold( $order_id, $status_from, $status_to, $order ) { | |
if($status_to === 'on-hold') { | |
if ( wcs_order_contains_subscription( $order, 'any' ) ) { | |
$subscriptions = wcs_get_subscriptions_for_order( $order, array( 'order_type' => array( 'any' ) ) ); | |
foreach( $subscriptions as $subscription_id => $subscription ){ | |
$subscription->update_status( 'active' ); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment