Skip to content

Early-bird lifetime licence: $199 once, for the first 200 buyers only. See the offer

Autocomplete WooCommerce orders without a plugin

Move paid orders of virtual products straight to Completed with one Snipfire snippet. It matches one of the plugin's modes; here is what it doesn't cover.

What Autocomplete WooCommerce Orders does

Autocomplete WooCommerce Orders marks orders as Completed automatically, with a choice of virtual-only orders or all paid orders. The plugin on WordPress.org

What the snippet does the same

  • Paid orders that contain only virtual products go straight to Completed instead of waiting in Processing.
  • It uses the same WooCommerce hook as the plugin, so it acts when a payment is confirmed (cards, PayPal and similar).
  • Like the free plugin, it leaves bank transfer, cheque and cash on delivery orders as they are.

What's different

  • The snippet only has the virtual products mode. The plugin also has a mode that completes all paid orders, including physical products.
  • The plugin has a settings screen to pick the mode. The snippet has no settings.

When to keep the plugin Keep the plugin if you want paid orders of physical products completed automatically as well.

The snippet: Complete paid orders of virtual products

Paid orders that contain only virtual products (services, memberships, tickets) go straight to Completed instead of waiting in Processing.

PHP
<?php

add_filter(
	'woocommerce_payment_complete_order_status',
	static function ( $status, $order_id, $order = null ) {
		$order = $order instanceof WC_Order ? $order : wc_get_order( $order_id );
		if ( 'processing' !== $status || ! $order ) {
			return $status;
		}
		foreach ( $order->get_items() as $item ) {
			$product = $item instanceof WC_Order_Item_Product ? $item->get_product() : null;
			if ( ! $product || ! $product->is_virtual() ) {
				return $status;
			}
		}
		return 'completed';
	},
	10,
	3
);

Notes, where it runs and what it was tested with

Switching from the plugin

  1. Install the snippet in Snipfire (it arrives switched off).
  2. Deactivate Autocomplete WooCommerce Orders.
  3. Switch the snippet on. Snipfire checks the code and test-loads your site first.
  4. Check the page it affects, then delete the plugin.

Move your snippets over this afternoon.

Importing changes nothing until you switch over, and your old shortcodes keep working.