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

How to Autocomplete Orders in WooCommerce?

Autocompleting orders in WooCommerce is typically used for digital products in WooCommerce. But why this autocompletion feature is equally vital in physical products as well? Nowadays if customers see their orders sit in a pending or processing state for too long, this can lead to cancellations and lost sales. This code will autocomplete all default woocommerce orders and orders made from all major payment providers, including PayPal, and Stripe.

Solution: Autocomplete Orders in WooCommerce

This code will automatically mark orders as “completed” once payment is confirmed, regardless of the product type or payment method. The code works for all the default payment methods and specifically for PayPal and Stripe as we have defined in this code.

add_action('woocommerce_thankyou', 'ts_custom_woocommerce_auto_complete_order');

function ts_custom_woocommerce_auto_complete_order($order_id) {
    if (!$order_id) {
        return;
    }

    $order = wc_get_order($order_id);

    // Define the payment methods for which orders should be auto-completed
    $auto_complete_payment_methods = array('stripe', 'ppcp-gateway', 'bacs', 'cod', 'cheque'); // Include all necessary payment methods

    // Check if the order payment method is in the defined array
    if (in_array($order->get_payment_method(), $auto_complete_payment_methods)) {
        // Auto-complete if the order is currently in 'processing' or 'on-hold' status
        if ($order->get_status() === 'processing' || $order->get_status() === 'on-hold') {
            $order->update_status('completed');
        }
    }
}

Output

When a customer buys something from your store, the order gets automatically marked as “completed” once the payment is successful. This means they won’t have to wait around wondering what’s happening with their order.

Now, you would have known how easy it is to autocomplete order in your WooCommerce store. But what happens when customers request refunds? When you have multiple orders to refund, it’s difficult to refund orders one by one right. No worries! We have also covered this customization that will show you how to refund multiple orders via bulk actions in WooCommerce, making it just as efficient as completing orders. With just a few clicks, you can handle multiple refunds, saving you time and reducing stress.

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