Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sisaacrussell/69cdae205d585d778fe47d20769cc956 to your computer and use it in GitHub Desktop.
Save sisaacrussell/69cdae205d585d778fe47d20769cc956 to your computer and use it in GitHub Desktop.
<?php
/**
* Autocomplete orders with virtual products (WC 2.2+)
*
* @see https://metorik.com/blog/autocomplete-all-the-orders-in-woocommerce
*/
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;
}
add_filter( 'woocommerce_thankyou', 'bryce_autocomplete_virtual_orders', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment