Created
November 26, 2014 07:54
-
-
Save bryceadams/da8c0eaf9e63a4a695aa to your computer and use it in GitHub Desktop.
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
<?php | |
/** | |
* Autocomplete orders with virtual products (WC 2.2+) | |
*/ | |
add_filter( 'woocommerce_payment_complete_order_status', 'bryce_autocomplete_virtual_orders', 10, 2 ); | |
function bryce_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
I wasn't able to get this gist working in wooCommerce 2.5.5, but I found a way that works, based on the code above and the code on this page https://docs.woothemes.com/document/automatically-complete-orders/
However, I have only tested this with virtual products, so I don't know how it will affect non virtual products.