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.


How to Allow Customers to Complete a Processing Order in WooCommerce? - Tyche Softwares

Adding the Confirm Order Button to My account > view Order  page in WooCommerce

The below updated code will allow you to place the confirm order button directly on the Woocommerce my account view orders page. In the modified code we have used the filter ‘woocommerce_order_details_after_order_table’ action hook and the wc_get_endpoint_url() function, explicitly pointing to the current order’s View Order page. By placing the button only on the View Order page, customers can review order details such as items purchased, shipping address, and payment method and then confirm the order.

add_action( 'woocommerce_order_details_after_order_table', 'ts_confirm_order_my_account_orders_actions' );

function ts_confirm_order_my_account_orders_actions( $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>';
    }
}

The ouput image below ensures that the button is specifically added after the order details table on the View Order page.

How to Allow Customers to Complete a Processing Order in WooCommerce? - Tyche Softwares


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:

Subscribe
Notify of
5 Comments
Newest
Oldest
Inline Feedbacks
View all comments
huo
14 days ago

How can I place this button on the “My Account” > “Orders” > “View Orders” page?

huo
12 days ago
Reply to  Saranya

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.

huo
12 days ago
Reply to  Saranya

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' => __(… Read more »

5
0
Would love your thoughts, please comment.x
()
x