Created
April 6, 2013 07:49
-
-
Save DevinWalker/5325330 to your computer and use it in GitHub Desktop.
WooCommerce Mark Virtual Orders as Complete
This file contains 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
//Mark Virtual Orders as Complete | |
add_filter( 'woocommerce_payment_complete_order_status', 'virtual_order_payment_complete_order_status', 10, 2 ); | |
function virtual_order_payment_complete_order_status( $order_status, $order_id ) { | |
$order = new WC_Order( $order_id ); | |
if ( $order_status == 'processing' && | |
( $order->status == 'on-hold' || $order->status == 'pending' || $order->status == 'failed' ) ) { | |
$virtual_order = true; | |
if ( count( $order->get_items() ) > 0 ) { | |
foreach( $order->get_items() as $item ) { | |
if ( $item['id'] > 0 ) { | |
$_product = $order->get_product_from_item( $item ); | |
if ( ! $_product->is_virtual() ) { | |
$virtual_order = false; | |
break; | |
} | |
} | |
} | |
} | |
// virtual order, mark as completed | |
if ( $virtual_order ) { | |
return 'completed'; | |
} | |
} | |
// non-virtual 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