Order Again Button on My Account > Orders WooCommerce

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.

Categories

Related Blogs

Add Custom Product Data Tab

Learn how to enhance your WooCommerce product editor by adding a custom product data tab. Follow a step-by-step guide using the woocommerce_product_data_tabs filter and the woocommerce_product_data_panels action. Create a custom tab with your desired label, and include your own fields or content within the panel. Customize your product data to collect and display additional information, providing a tailored experience for your WooCommerce products.

How To add custom product data tabs in WooCommerce

To add custom product data tabs in WooCommerce, you can use the woocommerce_product_data_tabs and woocommerce_product_data_panels hooks. These hooks allow you to add new tabs to the product edit page in the WooCommerce admin area. Here’s a step-by-step guide on how to achieve this: