Skip to content

Instantly share code, notes, and snippets.

@jrick1229
Last active November 17, 2021 15:18
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 jrick1229/1faa7e907216aa32e8dc24d37cc6d4a4 to your computer and use it in GitHub Desktop.
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.
<?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