Created
November 30, 2018 13:10
-
-
Save vanbo/d2032ec46c8f381a7a521b93043f3ba7 to your computer and use it in GitHub Desktop.
WooCommerce Orders with virtual and downloadable products need processing
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
/** | |
* 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; | |
} |
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
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.