You have your duplicate_line_items()
function written so that the items from the first parameter, $source_order
are added to the second parameter, $new_order
, but in your first block of code you’re passing the old order as the 2nd parameter:
duplicate_line_items($new_order, $old_order);
So all the items from $new_order
are being added to $old_order
, not the other way round.
Make sure you’re using the variables consistently:
duplicate_line_items( $old_order, $new_order );
Maybe name your variables in duplicate_line_items()
a bit more clearly too:
function duplicate_line_items( $source_order, $target_order ) {
foreach ( $source_order->get_items() as $item ) {
$target_order->add_item( $item );
}
$target_order->save();
}
So with those two changes you’re properly setting $old_order
as the $source_order
and $new_order
as the $target_order
.
Related Posts:
- How to check if is in cart page? [closed]
- Display single product attribute value on Shop page (Woocommerce)
- Woocommerce 3.1 Add product image to order confirmation email not working
- Woocommerce: show default variation price is products list?
- display available size on hover, in woocommerce shop page [closed]
- WooCommerce add_to_cart url not working [closed]
- How to Add Product Variation with Multiple Images via WooCommerce REST API
- How to build wordpress site which will have location based services & products?
- WooCommerce: Adding Order Item Meta Data That’s Hidden
- Redirect user after login through woocommerce login page to page with his/her username?
- WooCommerce restore stock on order cancel
- Woocoomerce product category count including subcategories
- WordPress select field – show current value?
- Get the category ID in checkout page woocomerce
- “Cannot read property ‘replace’ of undefined” Javascript error when trying to add attribute terms from add product page [closed]
- Order list woocommerce Orders based on meta for custom status
- WooCommerce product taxonomies and menu export
- Javascript / Ajax Error After Migrating To New Domain Name
- How can i stop woocommerce checkout event based on api request result?
- WordPress Twenty Seventeen header image size not responsive for mobile
- WooCommerce back-end very slow takes 10 seconds to load, slow queries
- Woocommerce custom meta fields, sort by date
- jquery.validation.js is not working in woocommerce checkout page form
- Delete cookie when changing url (when navigating away from specific page of website)
- multi-vender wooCommerce ability to separate products based on zip code [closed]
- Hide account tab to certain users
- How to Update the Order-Items While Editing an Order on the WooCommerce Admin Order Screen [closed]
- I want to run a script only once on a ‘thank you’ page
- search customers in front end by billing data
- Is it safe to have 2 mysql users?
- update_post_meta not work [closed]
- How to set a default value in a meta box
- Can I have one picture for all sizes in a product with Woocommerce?
- Adjust Price Display for Variable Product in Woocommerce [closed]
- Woocommerce password Reset
- Unable to pull in custom product attribute in shortcode [closed]
- Woocommerce redirect “add to cart” button to a contact form with product information to get a inquiry
- How to remove WooCommerce Plugin some specific features [closed]
- How to remove product attribute row woocommerce using code
- override the default WooCommerce products search form
- How can I override wp_price woocommerce function in my theme
- Woocommerce : read [max_qty] using backorder
- Woocommerce Product permalinks “product” word is not working
- Conditionally run function based on custom meta value?
- Woocommerce checkout required field error
- Setting a default variation for each product on the child theme functions.php file
- Issue with WordPress customize
- Group product by Instance ID
- WordPress woocommerce new order email not working
- WooCommerce add extra price to products by each category
- HTTP API CALLS issue on Woocommerce WordPress
- Woocommerce checkout page issue – Payment methods not loading – strange “Credit/Debit Card Secure Payment” form
- Sort products by Sale price and stock status
- Pagination in woocommerce – Limiting page-numbers
- Syncing WP Database Changes Between Environments: How To Handle Merging w/o touching database
- Show shipping class in admin order list
- Change order of combined product tabs
- Display notice on WooCommerce emails depending on chosen shipping option
- Impossible to create a new WooCommerce customer using Rest API
- edit URL of search result
- WooCommerce Stripe Test mode
- Woocommerce add_to_cart() then wp_safe_redirect() fails
- How to make phone number become whatsapp link in back-end order details woocommerce
- Check if product variation image is from the variation itself or from the parent
- How to show variations only which are in stock on shop page in woocommerce?
- select2 & selectWoo Not Loading Options
- How to use products shortcode in taxonomy-product_cat with multiple columns?
- Position WooCommerce basket and pricing
- Display Products Associated with Specific Attribute [closed]
- Add Previous | Next arrows near to related products
- Images not showing on site – Even though they are there
- How to know the page from which a product is added to the cart? – WooCommerce
- How to add contact seller button in product page
- Would it be ok if i had only 1 main woocommerce category?
- Conditionnaly replace “Read more” text WooCommerce products
- WooCommerce/Authorize.net interface problem
- Using category and its sub-categories products attributes as filter in products pages
- WooCommerce one time checkout pop up
- How to add capabilities for editor type user to access admin section
- woocommerce Shortcodes – Change display between mobile and Desktop
- Add multiple products to woocommerce cart
- Advanced Custom Fields missing Woocomerce in Rules
- woocommerce displaying products of a specific page
- How to display woocommerce products of one wordpress account in another wordpress account?
- Woocommerce Custom Rewrite Rules Array – Subcategories
- Woocommerce product listing design issues
- How to get an Array from “select” field in advanced custom fields
- change text “free shipping” in WooCommerce [closed]
- Change woocommerce one category image size
- How to edit schema.org markup of WooCommerce?
- Add woocommerce.css in template?
- How to change redirect code? [duplicate]
- Can I remove WooCommerce specific product categories from shop managers?
- Fetch products with filter by similar categories at same time
- Trying query woocommerce product order by menu order and stock status
- editing product page template – getting template for related products not working
- Woocommerce | I want to the button ‘Add to Cart’ on the (all) product-page changed by just ‘open product’ button
- Adding line breaks in WooCommerce order processing emails
- Disable Woocommerce Block Editor
- Woocommerce backend sorting product drag drop by menu_order to date