Skip to content

Instantly share code, notes, and snippets.

@woogist
Created July 24, 2015 10:13
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 woogist/7c1f6c25347ea1c35215 to your computer and use it in GitHub Desktop.
Save woogist/7c1f6c25347ea1c35215 to your computer and use it in GitHub Desktop.
add_filter( '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 );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment