Skip to content

Instantly share code, notes, and snippets.

@vanbo
Created November 30, 2018 13:10
Show Gist options
  • Select an option

  • Save vanbo/d2032ec46c8f381a7a521b93043f3ba7 to your computer and use it in GitHub Desktop.

Select an option

Save vanbo/d2032ec46c8f381a7a521b93043f3ba7 to your computer and use it in GitHub Desktop.
WooCommerce Orders with virtual and downloadable products need processing
/**
* Orders containing virtual or processing products only will be set to Completed essentially skipping the Processing status.
* If you need those orders to first be set to Processing:
* 1. Use the code below to have WooCommerce mark the order as Processing
* 2. Go to WooCommerce > Settings > Products > Downloadable Products > Uncheck the checkbox "Grant access to downloadable products after payment" > Save
*
* This process will mark the orders as Processing and wait until the order is in Completed status before grants a download access
*/
add_action( 'woocommerce_order_item_needs_processing', 'prefix_item_need_processing', 10, 3 );
function prefix_item_need_processing( $needs_procesing, $product, $order_id ) {
// Check if the product is virtual and downloadable
$is_virtual_downloadable_item = $product->is_downloadable() && $product->is_virtual();
// If the product is virtual and downloadable, decide if it needs processing, meaning the order will first be set to Processing
if ( $is_virtual_downloadable_item ) {
$needs_procesing = true;
}
return $needs_procesing;
}
@krgauravit007

krgauravit007 commented May 3, 2020

Copy link
Copy Markdown

I need help On this.
I need to put Non Virtual but Downloadable to Completed . But if order has Regular and downloadable both, it should be processing.
Pl help.

@vanbo

vanbo commented May 3, 2020

Copy link
Copy Markdown
Author

This filter is for the order item itself. You need "woocommerce_payment_complete_order_status"($order_id, $order) filter to set the status of the order when "payment_complete" is called. Loop through the items and return the status you need to set the order to (i.e. 'processing' or 'completed').

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment