Home » WooCommerce: Let Customers Complete a Processing Order

WooCommerce: Let Customers Complete a Processing Order

by adminkys

An order can be marked as “completed” only by the WooCommerce store manager – manually. In certain cases, this operation may be automatic i.e. for downloadable orders.

However, what if we want our customers to complete (confirm) their processing order instead? Well, this is quite easy: we display a “CONFIRM ORDER” button under My Account > Orders, and on click some code triggers the status change. Enjoy!

If the order is in “processing” status, the customer now sees a new “Confirm Order” button. On click, the order is automatically marked as “completed”!

PHP Snippet: “Confirm Order” Button @ My Account > Orders

/**
 * @snippet       Confirm Order Button | WooCommerce My Account
 * @how-to        Get tutoraspire.com FREE
 * @author        Tutor Aspire
 * @testedwith    WooCommerce 6
 * @donate $9     https://www.tutoraspire.com
 */

add_filter( 'woocommerce_my_account_my_orders_actions', 'tutoraspire_confirm_order_my_account_orders_actions', 9999, 2 );
  
function tutoraspire_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', 'tutoraspire_on_confirm_order_click_complete_order' );
   
function tutoraspire_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' );
    }
}

You may also like