🚀 Is building a website too difficult? Let me guide you step by step—Learn about the 「Naibabiji WordPress Website Building Coaching Service」 →

Methods for Automatically Completing WooCommerce Orders to Achieve Automatic Shipping

Yesterday, a friend consulted Naiba. HisWooCommerce automatic key delivery functionfailed. After payment, the status displayed was 'Pending', requiring the administrator to manually click 'Send' in the backend for the system to email the serial number to the customer. The reason for this issue is actually quite simple: WooCommerce's workflow is designed so that after a user pays, the default status is 'Processing'. Only after the administrator processes it will it be 'Completed' (because it involves situations like shipping). However, don't worry. Naiba shares heretwo 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 download and install the plugin via the link below.Download Link2. Activate the plugin and enter the WooCommerce settings interface. 3. Set and save in the 'Autocomplete Orders' section.https://wordpress.org/plugins/autocomplete-woocommerce-orders/Autocomplete WooCommerce Orders supports separate settings for whether to automatically complete physical orders and virtual orders, and is compatible with most payment gateways. You can use it with confidence. If you are not satisfied with this free plugin, you can also try theofficial 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 Snippets
add_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 thewoocommerce_order_status_changedThis hook determines whether an order is completed. For any order that is not Cash on Delivery (cod), it will automatically be marked as completed upon payment receipt. The default WooCommerce payment method IDs (which you can modify in the code above) are: Direct Bank Transfer (bacs), Check Payments (cheque), Cash on Delivery (cod), and PayPal (paypal).
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' );
		}
	}
}
The following code checks if the product is a virtual product. If it is, the order is automatically completed.

🚀 Still feeling confused after reading the tutorial? Let me guide you step-by-step instead.

「Naibabiji WordPress Website Building Coaching」 — From selecting a domain and purchasing hosting to installing themes and publishing posts, I「ll guide you through every step, helping you avoid detours and reach your goals directly.

👉 Learn about Website Building Coaching Service
🔒

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.

×
二维码

Scan to Follow