Blog

2 easy ways to clone/duplicate customer orders in WooCommerce

duplicate customer orders
Table of Contents

WooCommerce clone order is a feature that allows store managers to create a copy of one or more orders registered on the site as a new order. This means that all the values of the previous order are exactly repeated in the duplicated order, and the site manager only has to change the minor information, such as the date of the order if needed.

By duplicating customer orders in WooCommerce instead of creating a new order and entering the values of all order fields such as billing address, shipping address, etc., site owners can save their time and effort.

In the default options of WooCommerce, it is not possible to clone many customer orders at once, but you must open each order page individually. This is why most site owners need to use the duplicate customer order plugin in WooCommerce.

In this post, we will first show you how to do WooCommerce duplicate orders through coding, and then we will introduce you to the bulk edit orders plugin, with the help of which you can clone customer orders with one click.

Use PHP code for WooCommerce clone order

Php codes are one of the useful methods for customizing WordPress websites. However, if you need to become more familiar with coding, it makes sense to get help from an expert to add any code to your website. We also recommend you back up your site before adding a custom code snippet to copy/duplicate WooCommerce orders. 

If you take all reasonable precautions to prevent potential damages, use the following code for WooCommerce clone order:

function ithemeland_duplicate_order( $original_order_id ) {

    // Load Original Order
    $original_order = wc_get_order( $original_order_id );
    $user_id = $original_order->get_user_id();

    // Setup Cart
    WC()->frontend_includes();
    WC()->session = new WC_Session_Handler();
    WC()->session->init();
    WC()->customer = new WC_Customer( $user_id, true );
    WC()->cart = new WC_Cart();

    // Setup New Order
    $checkout = WC()->checkout();
    WC()->cart->calculate_totals();
    $order_id = $checkout->create_order( [ ] );
    $order = wc_get_order( $order_id );
    update_post_meta( $order_id, '_customer_user', get_current_user_id() );

    // Header
    update_post_meta( $order_id, '_order_shipping', get_post_meta($original_order_id, '_order_shipping', true) );
    update_post_meta( $order_id, '_order_discount', get_post_meta($original_order_id, '_order_discount', true) );
    update_post_meta( $order_id, '_cart_discount', get_post_meta($original_order_id, '_cart_discount', true) );
    update_post_meta( $order_id, '_order_tax', get_post_meta($original_order_id, '_order_tax', true) );
    update_post_meta( $order_id, '_order_shipping_tax', get_post_meta($original_order_id, '_order_shipping_tax', true) );
    update_post_meta( $order_id, '_order_total', get_post_meta($original_order_id, '_order_total', true) );
    update_post_meta( $order_id, '_order_key', 'wc_' . apply_filters('WooCommerce_generate_order_key', uniqid( 'order_' ) ) );
    update_post_meta( $order_id, '_customer_user',get_post_meta($original_order_id, '_customer_user', true) );
         
    update_post_meta( $order_id, '_order_currency', get_post_meta($original_order_id, '_order_currency', true) );
    update_post_meta( $order_id, '_prices_include_tax', get_post_meta($original_order_id, '_prices_include_tax', true) );
    update_post_meta( $order_id, '_customer_ip_address', get_post_meta($original_order_id, '_customer_ip_address', true) );
    update_post_meta( $order_id, '_customer_user_agent', get_post_meta($original_order_id, '_customer_user_agent', true) );

    // Billing
    update_post_meta( $order_id, '_billing_city', get_post_meta($original_order_id, '_billing_city', true));
    update_post_meta( $order_id, '_billing_state', get_post_meta($original_order_id, '_billing_state', true));
    update_post_meta( $order_id, '_billing_postcode', get_post_meta($original_order_id, '_billing_postcode', true));
    update_post_meta( $order_id, '_billing_email', get_post_meta($original_order_id, '_billing_email', true));
    update_post_meta( $order_id, '_billing_phone', get_post_meta($original_order_id, '_billing_phone', true));
    update_post_meta( $order_id, '_billing_address_1', get_post_meta($original_order_id, '_billing_address_1', true));
    update_post_meta( $order_id, '_billing_address_2', get_post_meta($original_order_id, '_billing_address_2', true));
    update_post_meta( $order_id, '_billing_country', get_post_meta($original_order_id, '_billing_country', true));
    update_post_meta( $order_id, '_billing_first_name', get_post_meta($original_order_id, '_billing_first_name', true));
    update_post_meta( $order_id, '_billing_last_name', get_post_meta($original_order_id, '_billing_last_name', true));
    update_post_meta( $order_id, '_billing_company', get_post_meta($original_order_id, '_billing_company', true));

    // Shipping
    update_post_meta( $order_id, '_shipping_country', get_post_meta($original_order_id, '_shipping_country', true));
    update_post_meta( $order_id, '_shipping_first_name', get_post_meta($original_order_id,  '_shipping_first_name', true));
    update_post_meta( $order_id, '_shipping_last_name', get_post_meta($original_order_id, '_shipping_last_name', true));
    update_post_meta( $order_id, '_shipping_company', get_post_meta($original_order_id, '_shipping_company', true));
    update_post_meta( $order_id, '_shipping_address_1', get_post_meta($original_order_id, '_shipping_address_1', true));
    update_post_meta( $order_id, '_shipping_address_2', get_post_meta($original_order_id, '_shipping_address_2', true));
    update_post_meta( $order_id, '_shipping_city', get_post_meta($original_order_id, '_shipping_city', true));
    update_post_meta( $order_id, '_shipping_state', get_post_meta($original_order_id, '_shipping_state', true));
    update_post_meta( $order_id, '_shipping_postcode', get_post_meta($original_order_id, '_shipping_postcode', true));

// Shipping Items
   $original_order_shipping_items = $original_order->get_items( 'shipping' );
foreach ( $original_order_shipping_items as $original_order_shipping_item ) {
    $item_id = wc_add_order_item( $order_id, array(
    'order_item_name' => $original_order_shipping_item['name'],
    'order_item_type' => 'shipping'
    ) );
    if ( $item_id ) {
        wc_add_order_item_meta( $item_id, 'cost', wc_format_decimal( $original_order_shipping_item['cost'] ) );
    }
}

// Coupons
$original_order_coupons = $original_order->get_items( 'coupon' );
foreach ( $original_order_coupons as $original_order_coupon ) {
    $item_id = wc_add_order_item( $order_id, array(
    'order_item_name' => $original_order_coupon['name'],
    'order_item_type' => 'coupon'
    ) );
   if ( $item_id ) {
       wc_add_order_item_meta( $item_id, 'discount_amount', $original_order_coupon['discount_amount'] );
   }
}

// Payment
update_post_meta( $order_id, '_payment_method', get_post_meta( $original_order_id, '_payment_method', true ) );
update_post_meta( $order_id, '_payment_method_title', get_post_meta( $original_order_id, '_payment_method_title', true ) );
update_post_meta( $order_id, 'Transaction ID', get_post_meta( $original_order_id, 'Transaction ID', true ) );

// Line Items
foreach( $original_order->get_items() as $originalOrderItem ) {
    $itemName = $originalOrderItem['name'];
    $qty = $originalOrderItem['qty'];
    $lineTotal = $originalOrderItem['line_total'];
    $lineTax = $originalOrderItem['line_tax'];
    $productID = $originalOrderItem['product_id'];
    $item_id = wc_add_order_item( $order_id, array(
    'order_item_name' => $itemName,
    'order_item_type' => 'line_item'
    ) );
    wc_add_order_item_meta( $item_id, '_qty', $qty );
    wc_add_order_item_meta( $item_id, '_tax_class', $originalOrderItem['tax_class'] );
    wc_add_order_item_meta( $item_id, '_product_id', $productID );
    wc_add_order_item_meta( $item_id, '_variation_id', $originalOrderItem['variation_id'] );
    wc_add_order_item_meta( $item_id, '_line_subtotal', wc_format_decimal( $lineTotal ) );
    wc_add_order_item_meta( $item_id, '_line_total', wc_format_decimal( $lineTotal ) );
    wc_add_order_item_meta( $item_id, '_line_tax', wc_format_decimal( $lineTax ) );
    wc_add_order_item_meta( $item_id, '_line_subtotal_tax', wc_format_decimal( $originalOrderItem['line_subtotal_tax'] ) );
}

// Close New Order
$order->calculate_totals();
$order->payment_complete();
// Note
$order->update_status( 'processing' );
$message = sprintf(
'This order was duplicated from order %d.',
$original_order_id
);
$order->add_order_note( $message );

// Return
return $order_id;
}

To run this code on your WordPress website, it is better to install the Code Snippets plugin and then go to the address below:

WP Admin > Snippets > Add New

Now, copy the code mentioned above and paste it into the website.

When you customize the code as you need and choose where to show the result – back end or front end, press the “Save and Activate” button.

By running this code, you can write the ID of any order in your online store to duplicate it.

Despite the fact that you need to have special skills to use the PHP codes, the time and effort spent to write and add a code to the website is not worth it. For example, there is no option for finding and filtering the orders you want to duplicate in this code. So, you have to add many code lines to customize it for your purpose.

If you are looking for a straightforward way to duplicate orders in WooCommerce, your ultimate solution is the WooCommerce bulk edit orders plugin. To learn how this duplicate customer order plugin can simplify the process of cloning orders, continue reading.

Use the orders bulk edit plugin for WooCommerce duplicate orders

The WooCommerce orders bulk edit plugin comes with a lot of amazing features for bulk editing, bulk removing, or duplicating WooCommerce orders. The powerful Filter Form designed for this plugin enables you to find and filter the desired orders quickly. Another useful tool provided in this plugin is a specific button helping store managers clone customer orders of WooCommerce with one click.

Let’s see how this plugin makes copying multiple WooCommerce orders at once easier.

Step 1: Download and install the plugin

The first step to use the orders bulk edit plugin is to download and install it. After installing and activating your WordPress website, this plugin adds a new item to your WordPress dashboard called iT Bulk Editing.

WooCommerce order bulk edit

If you press Woo orders from this new tab, you will be led to the main page of the plugin.

select woo orders menu in bulk edit plugin WooCommerce

On this page, there is a list of all orders in a table with a comprehensive toolbar on top of it. The items available in the toolbar have many functions, allowing you to manage the orders on your WooCommerce store easily. However, to fulfill the purpose of this tutorial, you just need to use the Filter Form and Duplicate buttons from the toolbar.

toolbar menu in bulk edit orders plugin

Read more to find out how to clone/duplicate customer orders in WooCommerce with these tools.

Step 2: Filter the desired orders

The first icon in the toolbar of the WooCommerce orders bulk edit plugin is Filter. By pressing the icon, you have access to a comprehensive Filter Form supported by all fields of WooCommerce orders as well as custom fields. 

To help you find the WooCommerce fields faster, the Filter Form is divided into seven tabs, including:

  • General
  • Billing
  • Shipping 
  • Pricing 
  • Items
  • Other Fields
  • Custom Fields
general tab in filter form bulk edit orders plugin

So, you can find the right field(s) for filtering just with a quick look and limit the orders for duplicating by pressing Get Orders.

For example, if you want to filter the orders based on the billing last name of your customers and then clone customer orders in WooCommerce, follow the below instructions:

  1. Open Filter Form and go to the Billing tab.
  2. Find the Billing Last Name field, open the first dropdown list, and choose Exact.
  3. Write the last name of your customer in the following box –Smith in this example.
  4. Press the Get Orders button.
select smith option in billing last name field bulk edit orders plugin

Now, you can see a list of all orders placed with Smith in the order table. 

Step 3: Select desired orders and clone customer orders WooCommerce

After filtering your desired orders, to use the WooCommerce duplicate orders tool in the plugin, follow the below instructions:

  1. Select some or all filtered orders in the table.
  2. Click on the Duplicate Orders button.
mark all ID and select duplicate button in orders WooCommerce
  1. In the pop-up page that appears on the screen, set how many times you want to copy WooCommerce orders. It is possible to either write a number manually or increase/decrease it by up/down arrows.
  2. Press the Start Duplicate button.
select three item to duplicate in orders WooCommerce

That’s it. The plugin will automatically create the new orders and copy all information of the selected orders to them.

Step 4: Inline edit the new orders

The WooCommerce bulk edit orders plugin has many useful features allowing you to inline edit or bulk edit any features of the new orders. For example, if you want to edit the status of new orders, you can easily:

  • Open the Column Profile Form.
  • Mark the Status field to be displayed in the table.
column profile tab in orders WooCommerce
  • Open the Status field in the table and select one of the order statuses from the list.
select completed option in status column in orders WooCommerce
WooCommerce order bulk edit

Why do you need to duplicate customer orders in WooCommerce?

When you have a small store, and the number of your orders is limited, creating a duplicate order with WooCommerce will not cause you many problems. But as your store grows, the number of duplicate orders increases, and creating similar orders with most of the same information becomes a long and tedious process.

In this situation, you should use the clone customer order method in WooCommerce to register duplicate orders that have the same details from the same customers. That way, you don’t have to enter duplicate information over and over again every time you place an order. The other reasons for using WooCommerce duplicate order methods are to save time and prevent any mistakes when copying the order information.

Unfortunately, the default options in WooCommerce do not let you filter and duplicate multiple orders at once. So, you may need to use a duplicate customer order plugin to do this task easily and quickly.

Conclusion

If your store has many loyal customers who regularly order the same products from your store, placing repeat orders with the same details from the same customers will be a time-consuming process. To save your time and effort, you need to use the duplicate customer order plugin in WooCommerce. In this post, we introduced you to the WooCommerce orders bulk edit plugin so that you can duplicate WooCommerce orders in a few seconds with its practical tools.

Leave a Reply

Your email address will not be published. Required fields are marked *

Shopping cart
Sign in

No account yet?

We use cookies to improve your experience on our website. By browsing this website, you agree to our use of cookies.

Start typing to see products you are looking for.