WordPress.org

Ready to get started?Download WordPress

Forums

WooCommerce - excelling eCommerce
Woocommerce duplicate order via Class API? (4 posts)

  1. concordusapps
    Member
    Posted 8 months ago #

    I'm using Woocommerce to manage a number of orders. I have an action where I would like to duplicate an existing order. In other words, I want to create a new order that has a new order number but everything else is identical (user, billing info, items, totals, etc).

    I want to do it from the theme's functions.php file. I am using a woocommerce hook to trigger my custom function which currently finds the referenced order, then I need to create a duplicate of it (new order id of course).

    I thought to use WC_Order() to do it, but that doesn't capture items. I thought to write directly to the DB using $wpdb, but that is 4 tables to update with a whole lot of dependencies. Is there not something as simple as $new = new WC_Order(); $new->save(); ?

    http://wordpress.org/plugins/woocommerce/

  2. IgniteWoo
    Member
    Posted 8 months ago #

    This not trivial to accomplish. There are a few different approaches to take. You have to deal with the order post, order status taxonomy, order postmeta, order items, order item meta. There's no existing function to duplicate an order. Got a copy of WC Subscriptions? It duplicates orders to some extent. Might be a good example for you.

  3. Lucas Karpiuk
    Member
    Posted 8 months ago #

    shouldn't be too difficult to extract the code you need straight from the source:

    http://docs.woothemes.com/wc-apidocs/source-function-woocommerce_order_again.html#792-844

  4. IgniteWoo
    Member
    Posted 8 months ago #

    Oh that's cool - totally forgot about that! Thanks Lucas :-)

    That's a decent start. But it expects someone to run through checkout on the public site. So it only serves a beginning to actually get the order into the store DB.

    WooCommerce Subscriptions actually has code to totally dup an order from start to finish. Thus my suggestion to have a look at the code if possible.

Reply

You must log in to post.

About this Plugin

About this Topic