May 4, 2025

How to Add a “Reorder” Button in WooCommerce

This post explains how to implement a “Reorder” feature in WooCommerce, allowing customers to quickly place the same order again. This can significantly improve the shopping experience on stores that sell frequently repurchased items like consumables or groceries.

By default, WooCommerce does not provide a “Reorder” button in the account order list. Here’s how you can add one manually using code.


Step 1: Add the “Reorder” Button to the My Orders Page

Add the following code to your theme’s functions.php file. It uses the woocommerce_my_account_my_orders_actions filter to insert a “Reorder” button next to completed orders.

add_filter('woocommerce_my_account_my_orders_actions', 'wprs_add_reorder_button', 10, 2);
function wprs_add_reorder_button($actions, $order) {
    if ($order->has_status('completed')) {
        $actions['reorder'] = array(
            'url'  => wp_nonce_url(add_query_arg('reorder', $order->get_id()), 'woocommerce-reorder'),
            'name' => 'Reorder'
        );
    }
    return $actions;
}

Step 2: Handle the Reorder Request

When the customer clicks “Reorder”, we process their request by:

  1. Verifying the request with a nonce.
  2. Fetching the original order.
  3. (Optionally) Emptying the current cart.
  4. Checking each item for availability.
  5. Adding the available items back to the cart.
  6. Redirecting the customer to the cart page.

Add this code to the same functions.php file:

add_action('wp_loaded', 'wprs_handle_reorder_request', 20);
function wprs_handle_reorder_request() {
    if (!isset($_GET['reorder']) || !is_numeric($_GET['reorder'])) {
        return;
    }

    if (!wp_verify_nonce($_GET['_wpnonce'], 'woocommerce-reorder')) {
        wc_add_notice('Invalid request', 'error');
        wp_safe_redirect(wc_get_page_permalink('myaccount'));
        exit;
    }

    $order_id = absint($_GET['reorder']);
    $order = wc_get_order($order_id);

    if (!$order) {
        wc_add_notice('Order not found', 'error');
        wp_safe_redirect(wc_get_page_permalink('myaccount'));
        exit;
    }

    WC()->cart->empty_cart();

    foreach ($order->get_items() as $item) {
        $product_id   = $item->get_product_id();
        $variation_id = $item->get_variation_id();
        $quantity     = $item->get_quantity();

        $product = wc_get_product($product_id);
        if (!$product || !$product->is_purchasable() || !$product->is_in_stock()) {
            wc_add_notice(sprintf('"%s" is no longer available or out of stock.', $item->get_name()), 'error');
            continue;
        }

        if ($variation_id) {
            WC()->cart->add_to_cart($product_id, $quantity, $variation_id);
        } else {
            WC()->cart->add_to_cart($product_id, $quantity);
        }
    }

    wp_safe_redirect(wc_get_cart_url());
    exit;
}