The WooCommerce “Order Again” button displays for ‘completed’ orders on the Thank You page and View Order page. That’s a pity, because it would be useful to show it on the My Account > Orders page as well, as a custom “action”, same as the “View”, “Pay” (if pending), “Cancel” (if subscription), “Edit” (custom snippet), “Confirm” (custom snippet) buttons.
The good news is that we can code it ourselves! And just reuse most of the code we already wrote, as well as rely on the WooCommerce “listener” for the existing “Order Again” button. Enjoy!
PHP Snippet: Add “Order Again” Button to My Account > Orders Action (Completed Orders Only)
If you’re wondering how I came up with the ‘url’ code in the snippet below, I simply reused the exact same code of the woocommerce_order_again_button() function.
Also, somewhere in the Cart class, there is a “listener” that triggers when the button is clicked – see get_cart_from_session() – so because I’m using the exact same button URL, the listener triggers from the new button position as well.
/**
* @snippet Order Again @ My Account Orders
* @how-to businessbloomer.com/woocommerce-customization
* @author Rodolfo Melogli, Business Bloomer
* @compatible WooCommerce 6
* @community https://businessbloomer.com/club/
*/
add_filter( 'woocommerce_my_account_my_orders_actions', 'bbloomer_order_again_action', 9999, 2 );
function bbloomer_order_again_action( $actions, $order ) {
if ( $order->has_status( 'completed' ) ) {
$actions['order-again'] = array(
'url' => wp_nonce_url( add_query_arg( 'order_again', $order->get_id(), wc_get_cart_url() ), 'woocommerce-order_again' ),
'name' => __( 'Order again', 'woocommerce' ),
);
}
return $actions;
}
I don’t know how many times I used your PHP codes over my WordPress/Woocommerce website! Thanks a lot for sharing to the community!
Your code allows us to not have an extra plugin for a really simple functionality, not to pay for an extra plugin and it also helps non coders to understand better how PHP/Wordpress/Woocommerce works.
So thanks again for sharing with the community!
Thank you Max!
Hello Rodolfo, first of all, thanks for this snippet. We have tested this inside an eCommerce website me manage, but somethiing really weird happens after we click on the order again button: it redirects us to the Cart (as I believe it is suppose to be..) but then the cart is empty. Even if I have something in the cart before clicking the order again button (at any order available in my account, inside the Orders Tab).. the Cart gets always emptied. What could we do to solve this issue?
A cache issue maybe?
HI there, my client want a option and i hope i can explain it well.
situation: a client made an order. en later the same client want ot make an order again en then he needs to combine te orde in the checkout. so he want a button ” combine order” then he need to enter his order number of the first order” my client wants this so he can combine it in 1 shipping and the customer only pays 1 shipping. i hope you understand what my client need
Hello Michel, 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!
Hi seems to work but it is next to the view button. how could i add this down from the view button? Thanks
Thank you George! A bit of custom CSS would do in this case. Unfortunately this is specific to your theme so I can’t help here.