Yesterday, a friend consulted Naiba. He used
WooCommerce Automatic Serial Key Delivery FunctionFailed. After payment, the status displayed is pending. The administrator needs to manually click 'Send' in the backend for the system to send an email to the customer with the serial number. Actually, the reason for this issue is simple: WooCommerce's workflow is designed so that after a user pays, the default status is 'Processing'. The order is only completed after the administrator processes it (because it involves situations like shipping). However, don't worry. Naiba here shares
two effective methods to achieve automatic order completion.。
Method 1: Using a Plugin
We use the 'Autocomplete WooCommerce Orders' plugin to achieve automatic order completion. 1. Search for 'Autocomplete WooCommerce Orders' in the backend or click the link below to download and install the plugin.
Download Link2. Activate the plugin and enter the WooCommerce settings interface. 3. Set and save at the 'Autocomplete Orders' section.

'Autocomplete WooCommerce Orders' supports separate settings for whether to automatically complete physical orders and virtual orders. It is also compatible with most payment gateways, so you can use it with confidence. If you are not satisfied with this free plugin, you can also try
the official paid plugin.。
Method Two: Using Code
1. Add the following code to your website's theme functions file. If you don't know how to add it, you can use:
Safe Method to Add Code to the functions.php File: Code Snippetsadd_action('woocommerce_order_status_changed', 'ts_auto_complete_by_payment_method');
function ts_auto_complete_by_payment_method($order_id)
{
if ( ! $order_id ) {
return;
}
global $product;
$order = wc_get_order( $order_id );
if ($order->data['status'] == 'processing') {
$payment_method=$order->get_payment_method();
if ($payment_method!="cod")
{
$order->update_status( 'completed' );
}
}
}This code calls the
woocommerce_order_status_changedhook to determine if the order is completed. As long as it's not a Cash on Delivery order, it will be automatically marked as completed after payment is received. WooCommerce default payment method IDs (you can modify the code above yourself): Direct bank transfer (bacs), Check payments (cheque), Cash on delivery (cod), and PayPal (paypal). 2. The following code checks if it's a virtual product. If it is a virtual product, it automatically completes the order.
add_action('woocommerce_order_status_changed', 'ts_auto_complete_virtual');
function ts_auto_complete_virtual($order_id)
{
if ( ! $order_id ) {
return;
}
global $product;
$order = wc_get_order( $order_id );
if ($order->data['status'] == 'processing') {
$virtual_order = null;
if ( count( $order->get_items() ) > 0 ) {
foreach( $order->get_items() as $item ) {
if ( 'line_item' == $item['type'] ) {
$_product = $order->get_product_from_item( $item );
if ( ! $_product->is_virtual() ) {
// once we find one non-virtual product, break out of the loop
$virtual_order = false;
break;
}
else {
$virtual_order = true;
}
}
}
}
// if all are virtual products, mark as completed
if ( $virtual_order ) {
$order->update_status( 'completed' );
}
}
}Alright, the above are the methods shared by Naiba for WooCommerce automatic order completion. Hope it helps you.
Comments are closed
The comment function for this article is closed. If you have any questions, please feel free to contact us through other channels.