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!
PHP Snippet: “Confirm Order” Button @ My Account > Orders
/**
* @snippet Confirm Order Button | WooCommerce My Account
* @how-to businessbloomer.com/woocommerce-customization
* @author Rodolfo Melogli, Business Bloomer
* @testedwith WooCommerce 6
* @community https://businessbloomer.com/club/
*/
add_filter( 'woocommerce_my_account_my_orders_actions', 'bbloomer_confirm_order_my_account_orders_actions', 9999, 2 );
function bbloomer_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', 'bbloomer_on_confirm_order_click_complete_order' );
function bbloomer_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' );
}
}
Hello, thanks, this worked very well. I have a scenario where I have a “Ready For Pickup” custom status, and another custom status called “Ready For Pickup – Reminder”. I made a change to the slug in the OG code and got it to work for one or the other statuses, but I would like to set this up for both. I tried adding a second cloned snippet and changing the order status slug, but it will not activate. Is there a way to add both status triggers in the same code snippet?
Thanks in advance.
Brad, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Hello, Rodolfo. Great work as always!
I’m trying to create a button “Click me to complete this order” and place this on a private page, on the frontend, that managers have access. I already have the order object on this page. Any idea on how to run the
on the click of a button?
Thank you!
Hi William, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
How much would such a solution cost?
Hi Max, thanks so much for your comment! If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!