Skip to content

Instantly share code, notes, and snippets.

@apmwebdev
Last active April 25, 2019 18:55
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 apmwebdev/f7016715fa28efbdcda887d1b5fb5d2c to your computer and use it in GitHub Desktop.
Save apmwebdev/f7016715fa28efbdcda887d1b5fb5d2c to your computer and use it in GitHub Desktop.
WooCommerce Subscriptions - Delete cancelled subscription
add_action( 'woocommerce_subscription_status_updated' , 'delete_cancelled_subscription' , 10 , 3 );
function delete_cancelled_subscription( $subscription, $new_status, $old_status) {
if ($new_status == 'pending-cancel' || $new_status == 'cancelled') {
$subscription_id = $subscription->get_id();
wc_delete_shop_order_transients($subscription_id);
wp_delete_post($subscription_id);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment