To add an “Order Again” button on the WooCommerce My Account > Orders page, you can use hooks and filters to customize the order details table. The following steps will guide you through the process:
Step 1: Create a Custom Function Add the following code to your theme’s functions.php file or a custom plugin:
// Add "Order Again" button to the "My Account > Orders" page function custom_add_order_again_button($order_id) { $order = wc_get_order($order_id); // Check if the order is valid and if it is "completed" or "processing" if ($order && in_array($order->get_status(), array('completed', 'processing'))) { $order_again_url = wc_get_cart_url() . '?order_again=' . $order_id; echo '<a href="' . esc_url($order_again_url) . '" class="button order-again">' . __('Order Again', 'woocommerce') . '</a>'; } } add_action('woocommerce_my_account_my_orders_actions', 'custom_add_order_again_button');
Step 2: Save Changes and Test Save the changes to your functions.php file or custom plugin. Now, when you visit the “My Account > Orders” page in WooCommerce, you should see an “Order Again” button for each completed or processing order.
The “Order Again” button will allow customers to quickly add the products from the respective order to their cart and proceed to checkout, saving them the effort of manually searching for and adding each product again.
Please note that the “Order Again” button will only be displayed for orders with the “completed” or “processing” status, as these are typically the statuses for orders that have been successfully processed and can be reordered.