Skip to content

Instantly share code, notes, and snippets.

@digitalchild
Last active September 24, 2015 23:15
Show Gist options
  • Select an option

  • Save digitalchild/c4ffa253c3f625653cf6 to your computer and use it in GitHub Desktop.

Select an option

Save digitalchild/c4ffa253c3f625653cf6 to your computer and use it in GitHub Desktop.
Auto Complete Paid Orders if all products are virtual
<?php
// Place this in theme or your own agency plugin
add_filter( 'woocommerce_payment_complete_order_status', 'complete_paid_orders', 10, 2 );
/**
* Auto Complete Paid orders in WooCommerce
* only if all products are virtual in the order
*
* @author Jamie Madden <[email protected]>
* @return string order_status
*/
function complete_paid_orders( $order_status, $order_id ) {
$order = new WC_Order( $order_id );
$order_items = $order->get_items();
$virtual = false;
foreach ( $order_items as $item ) {
$product = new WC_Product( $item[ 'product_id' ] );
$virtual = ( $product->is_virtual() ) ? true : false;
}
if ( $virtual ) {
if ( $order_status == 'processing' && ( $order->status == 'on-hold' || $order->status == 'pending' || $order->status == 'failed' ) ) {
return 'completed';
}
}
return $order_status;
} // complete_paid_orders()
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment