Created
July 29, 2015 07:40
-
-
Save woogist/5332bcbece38de4fd47e to your computer and use it in GitHub Desktop.
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
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 ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Woogist,
Is this code still working ?
Thanks in advance