Description
Are you running a WooCommerce store that sells downloadable or digital products (software, scripts, images, designs, graphics, audio, video, etc)? Do you want to automate the process of marking orders as complete when all products in the order are downloadable? Look no further than our WooCommerce auto-complete script!
Our script adds a simple functionality to your site’s functions.php file that automatically changes the status of your WooCommerce orders from “Pending” to “Completed” if all the products in the order are downloadable and the order was paid. This feature saves you time and effort by eliminating the need to manually mark orders as complete when they only contain downloadable products.
Not only does this script increase efficiency, but it also improves the customer experience by instantly delivering digital products upon payment. No more waiting for manual confirmation or dealing with delayed processing times.
The script is easy to install, customize and use, and it integrates seamlessly with your WooCommerce store. Don’t let manual order processing slow you down – streamline your store’s operations and give your customers the experience they deserve with our WooCommerce auto-complete script!
WooCommerce Autocomplete Orders Script
Add the following script to your Child Theme’s functions.php file:
//script that checks the order and if it is paid and the order contains only downloadable items - automatically changes the order to Complete
add_action( 'woocommerce_thankyou', 'auto_complete_downloadable_orders', 10, 1 );
function auto_complete_downloadable_orders( $order_id ) {
// Get the order object
$order = wc_get_order( $order_id );
// Check if all products in the order are downloadable
$downloadable = true;
foreach ( $order->get_items() as $item ) {
if ( ! $item->get_product()->is_downloadable() ) {
$downloadable = false;
break;
}
}
// If all products in order are downloadable, mark the order as completed
if ( $downloadable ) {
$order->update_status( 'completed' );
}
}
The demo script shows an example of code that adds an action hook to the WooCommerce “thank you” page, which is displayed after an order is successfully placed. The auto_complete_downloadable_orders function is called when this page is loaded, and it checks whether all products in the order are downloadable. If they are, it updates the order status to “completed”. Note that this code only applies to orders that are initially in the “Pending” status. If you want to apply this behavior to all orders, you can change the woocommerce_thankyou action to woocommerce_order_status_changed and add an additional check to make sure the previous order status was “Pending”.
Reviews
There are no reviews yet.