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

How to Allow Customers to Complete a Processing Order in WooCommerce?

In WooCommerce, the completion of an order is a manual process done by the store manager. But in specific scenarios, such as with downloadable orders, this process may occur automatically.

Imagine this: What if we want to give our customers the ability to confirm their processing orders themselves? It’s simpler than you might think. Just by adding a “Confirm Order” button within My Account > Orders, customers can take control of the process with just a click.

Solution: Allow Customers to Complete a Processing Order in WooCommerce

add_filter( 'woocommerce_my_account_my_orders_actions', 'ts_confirm_order_my_account_orders_actions', 10, 2 );
   
function ts_confirm_order_my_account_orders_actions( $actions, $order ) {
    if ( $order->has_status( 'processing' ) ) {
        $actions['confirm-order'] = array(
            'url'  => wp_nonce_url( add_query_arg( array( 'confirm_order' => $order->get_id() ) ), 'woocommerce-confirm-order' ),
            'name' => __( 'Confirm Order', 'woocommerce' )
        );
    }
    return $actions;
}
   
add_action( 'template_redirect', 'ts_on_confirm_order_click_complete_order' );
    
function ts_on_confirm_order_click_complete_order( $order_id ) {
   if ( isset( $_GET['confirm_order'], $_GET['_wpnonce'] ) && is_user_logged_in() && wp_verify_nonce( wp_unslash( $_GET['_wpnonce'] ), 'woocommerce-confirm-order' ) ) {
        $order = wc_get_order( $_GET['confirm_order'] );
      $order->update_status( 'completed', 'Order confirmed by customer' );
    }
}

Output

The confirm order button is placed in the actions column of processing orders which will allow customers to confirm an order. Once the button is clicked, the order will be transitioned to completed status.



Along with giving customers the option to confirm the order, you can also add an ‘Order Again’ button in WooCommerce on My Account orders page. This will let the customer conveniently buy the product again if they want.

Browse more in: Code Snippets, WooCommerce How Tos, WooCommerce Tutorials

Share It:

0 thoughts on “How to Allow Customers to Complete a Processing Order in WooCommerce?

    1. Hi Huo,
      
      To place the button on the My Account > Orders > View Orders page, we’ve made some tweaks to the original code. You can find the updated code snippet below the heading: “Adding the Confirm Order Button to My Account > View Order Page in WooCommerce”

      1. Thank you very much for your code. I can test both ends of the code and it works independently. However, when I want it to be displayed on My Account > Orders and View Order page at the same time, it does not work properly and the website will display a white screen.

        1. To meet your requirement of displaying the “Confirm Order” button on both the My Account > Orders page and the My Account > View Order page, you’ll need to use a combination of the code for both pages. Finally, add the order confirmation logic code as shown in this screenshot-https://prnt.sc/RfCz2VcTVHJC
          While the combined code works fine on my setup when tested together, I’m unsure why it isn’t working on your site. It could be due to factors like theme or plugin conflicts, or any additional customizations made to your site.

          1. Thanks again for your reply I entered the code into big data and it said there was an error and gave me an answer like this, and I ran it fine.
            
            // Added "Confirm Order" button to the My Account Orders list
            add_filter( 'woocommerce_my_account_my_orders_actions', 'ts_add_confirm_order_button_to_my_orders', 10, 2 );
            function ts_add_confirm_order_button_to_my_orders( $actions, $order ) {
                if ( $order->has_status( 'processing' ) ) {
                    $actions['confirm-order'] = array(
                        'url'  => wp_nonce_url( add_query_arg( array( 'confirm_order' => $order->get_id() ), wc_get_page_permalink( 'myaccount' ) ), 'woocommerce-confirm-order' ),
                        'name' => __( 'Confirm Order', 'woocommerce' )
                    );
                }
                return $actions;
            }
             
            // Add a "Confirm Order" button at the bottom of the order details page
            add_action( 'woocommerce_order_details_after_order_table', 'ts_add_confirm_order_button_to_order_details' );
            function ts_add_confirm_order_button_to_order_details( $order ) {
                if ( $order->has_status( 'processing' ) ) {
                    $url = wp_nonce_url(
                        add_query_arg(
                            array( 'confirm_order' => $order->get_id() ),
                            wc_get_endpoint_url( 'view-order', $order->get_id(), wc_get_page_permalink( 'myaccount' ) )
                        ),
                        'woocommerce-confirm-order'
                    );
             
                    echo '<a href="' . esc_url( $url ) . '" class="button confirm-order-button">' . __( 'Confirm Order', 'woocommerce' ) . '</a>';
                }
            }
            
            

Leave a Reply to huo Cancel reply

Your email address will not be published. Required fields are marked *

Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible.

Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

By using our site, you acknowledge that you have read and understood our Privacy Policy and Terms & Conditions.