Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save zorem/3037fbf5332233209fcbcba647f2f477 to your computer and use it in GitHub Desktop.
Save zorem/3037fbf5332233209fcbcba647f2f477 to your computer and use it in GitHub Desktop.
The function is for change order status to competed if order is virtual and downloadable
<?php
add_filter( 'woocommerce_payment_complete_order_status', 'virtual_order_payment_complete_order_status', 10, 4 );
/*
* move processing to completed
*/
function virtual_order_payment_complete_order_status( $order_status, $order_id ) {
$order = wc_get_order( $order_id );
if ( 'processing' == $order_status ) {
$virtual_order = null;
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() && $product->is_downloadable()) {
// once we've found one non-virtual product we know we're done, break out of the loop
$virtual_order = true;
} else {
$virtual_order = false;
break;
}
}
}
}
// virtual order, mark as completed
if ( $virtual_order ) {
return 'custom-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