Last active
February 6, 2019 21:45
-
-
Save ericandrewlewis/6143779 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
<?php | |
add_filter( 'woocommerce_payment_complete_order_status', 'subscription_order_payment_onhold_order_status', 10, 2 ); | |
/** | |
* Catch new subscription orders, and put the order on-hold by default. | |
*/ | |
function subscription_order_payment_onhold_order_status( $order_status, $order_id ) { | |
$order = new WC_Order( $order_id ); | |
if ( 'processing' != $order_status || ( 'on-hold' != $order->status && 'pending' != $order->status && 'failed' != $order->status ) ) | |
return $order_status; | |
$subscription_order = false; | |
// If for some reason there are no items in the order, bail. | |
if ( empty( $order->get_items() ) ) | |
return $order_status; | |
foreach( $order->get_items() as $item ) { | |
if ( 'line_item' != $item['type'] ) | |
continue; | |
$_product = $order->get_product_from_item( $item ); | |
if ( $_product->is_subscription() ) { | |
// once we've found one subscription product we know we're done, break out of the loop | |
return 'on-hold'; | |
break; | |
} | |
} | |
// non-subscription order, return original status | |
return $order_status; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment