Anyone know how i could duplicate/copy an order from woocommmerce and create a new order from the old one?
I am working in a Payment gateway and after a payment has been made in a recurring subscription i will need to duplicate a new order and mark as paid!!!!
Is that possible?
Cheers.
When PayPal sends an IPN
subscr_payment
update to WooCommerce I’m using this code inside thevalid_paypal_standard_ipn_request
action to create new orders from existing orders. Once in a while the shipping info is empty on the new order. I’m not sure what’s causing that, but this is new code so it might be buggy.All the components of a WooCommerce order are here. I created this from the logic in
class-cw-checkout.php
create_order, but used an existing order to provide the values.You can copy all the order meta data first using wc_get_order_item_meta(), like this:
And you can add the copied metadata using add_post_meta()
After that you can copy all item meta keys with wc_get_order_item_meta(), like this:
And you can add the copied item metas using wc_add_order_item_meta()