Skip to content

Instantly share code, notes, and snippets.

@woogist
Created July 29, 2015 07:40
Show Gist options
  • Save woogist/5332bcbece38de4fd47e to your computer and use it in GitHub Desktop.
Save woogist/5332bcbece38de4fd47e to your computer and use it in GitHub Desktop.
add_action( 'updated_users_subscriptions_for_order', 'wc_subs_suspend_on_cod' );
function wc_subs_suspend_on_cod( $order ) {
if ( ! is_object( $order ) ) {
$order = new WC_Order( $order );
}
foreach ( WC_Subscriptions_Order::get_recurring_items( $order ) as $order_item ) {
$subscription_key = WC_Subscriptions_Manager::get_subscription_key( $order->id, WC_Subscriptions_Order::get_items_product_id( $order_item ) );
$payment_gateways = WC()->payment_gateways->payment_gateways();
$payment_gateway = isset( $payment_gateways[ $order->recurring_payment_method ] ) ? $payment_gateways[ $order->recurring_payment_method ] : '';
if ( $payment_gateway->id == 'cod' && $order->get_status() != 'completed' ) {
WC_Subscriptions_Manager::put_subscription_on_hold( $order->user_id, $subscription_key );
}
}
}
@maximeRoudier
Copy link

Hi Woogist,

Is this code still working ?

Thanks in advance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment