Created
June 5, 2017 16:32
-
-
Save DanielSantoro/201db735c484cc38c9ca40bc34b2461c to your computer and use it in GitHub Desktop.
Autocomplete Virtual Orders
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( 'woocommerce_payment_complete_order_status', 'woocustom_autocomplete_virtual_orders', 10, 2 ); | |
function woocustom_autocomplete_virtual_orders( $order_status, $order_id ) { | |
$order = wc_get_order( $order_id ); | |
if ('processing' == $order_status && ('on-hold' == $order->status || 'pending' == $order->status || 'failed' == $order->status)) { | |
$virtual_order = ''; | |
if ( count( $order->get_items() ) > 0 ) { | |
foreach ( $order->get_items() as $item ) { | |
if ( 'line_item' == $item['type'] ) { | |
$_product = $order->get_product_from_item( $item ); | |
if ( ! $_product->is_virtual() ) { | |
$virtual_order = false; | |
break; | |
} else { | |
$virtual_order = true; | |
} | |
} | |
} | |
} | |
if ( $virtual_order ) { | |
return 'completed'; | |
} | |
} | |
return $order_status; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment