Created
July 24, 2015 10:13
-
-
Save woogist/7c1f6c25347ea1c35215 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_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