Black Friday & Cyber Monday SUPER SALE ALL WEEK:
Grab 40% OFF on plugins
00 Days
00 Hours
00 Minutes
00 Seconds

How to Change Order Status for Downloadable Products in WooCommerce?

All virtual and downloaded products straightway goes to completed status once payment is done. This is the default behavior set by WooCommerce to process digital products. But if you wish to set some additional processing steps you may use a plugin or a custom code to achieve this.

Solution: Change Order Status For Downloadable Products

The code snippet below will help you to add an order status ‘processing’ if the order contains a downloadable product. In short, we are adding an additional workflow ‘processing’ rather than immediately marking it as ‘completed’ for downloadable products.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
add_action( 'woocommerce_order_status_changed', 'ts_change_status_downloads', 1 );
function ts_change_status_downloads( $order_id ){
// initiate the order
$order = wc_get_order( $order_id );
// let's suppose by default that all products are downloadable
$only_downloadable_products = true;
// loop through all products
foreach ($order->get_items() as $product_id => $product_data) {
// WC_Product object
$product = $product_data->get_product();
if ( !$product->is_downloadable() ) { // not downloadable
$only_downloadable_products = false;
break;
}
}
if( $only_downloadable_products == true ) {
$order->update_status('processing');
}
}
add_action( 'woocommerce_order_status_changed', 'ts_change_status_downloads', 1 ); function ts_change_status_downloads( $order_id ){ // initiate the order $order = wc_get_order( $order_id ); // let's suppose by default that all products are downloadable $only_downloadable_products = true; // loop through all products foreach ($order->get_items() as $product_id => $product_data) { // WC_Product object $product = $product_data->get_product(); if ( !$product->is_downloadable() ) { // not downloadable $only_downloadable_products = false; break; } } if( $only_downloadable_products == true ) { $order->update_status('processing'); } }
add_action( 'woocommerce_order_status_changed', 'ts_change_status_downloads', 1  );

function ts_change_status_downloads( $order_id ){

	// initiate the order
	$order = wc_get_order( $order_id );

	// let's suppose by default that all products are downloadable
	$only_downloadable_products = true;
	
	// loop through all products
	foreach ($order->get_items() as $product_id => $product_data) {

		// WC_Product object
		$product = $product_data->get_product();
		if ( !$product->is_downloadable() ) { // not downloadable
			$only_downloadable_products = false; 
			break;
		}
	}

	if( $only_downloadable_products == true ) {
		$order->update_status('processing');
	}
	
}

Output

When an order is placed that contains downloadable products the order status immediately goes to ‘processing’ regardless of the default assigned status ‘completed’.

How to Change Order Status for Downloadable Products in WooCommerce? - Tyche Softwares

Similarly, you can also set the status based on parameters such as product categories, tags and many more. You can check out here on how to customize WooCommerce order status based on Product Categories.

Browse more in: Code Snippets, WooCommerce How Tos, WooCommerce Tutorials

Share It:

Subscribe
Notify of


0 Comments
Newest
Oldest
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible.

Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

By using our site, you acknowledge that you have read and understood our Privacy Policy and Terms & Conditions.