0

I'm creating custom multi vendor script in my website. I've set authors (vendors) for woocommerce products and I want to set authors for orders too so I can determine which vendor's product sold.

I'm programmatically creating amazon and other market's orders so I can't use woocommerce thankyou function.

Simply I want to ask, how to hook into woocommerce order save function both works in frontend and backend?

exspet
  • 48
  • 2
  • 11

1 Answers1

1
  • You can try woocommerce_new_order (see).
  • You can also use order status based hooks, like woocommerce_order_status_completed or woocommerce_order_status_changed
  • woocommerce_checkout_create_order, woocommerce_checkout_create_order or woocommerce_payment_complete would be for checkout actions only (see)

All those hooks have the Order or order_id as a parameter or the new order status.

Mtxz
  • 3,749
  • 15
  • 29
  • does it fixes the issue? – Mtxz Aug 22 '18 at 01:46
  • Hi, actually its works. But I can't get the product id with that snipped: `add_action( 'woocommerce_new_order', 'set_author_for_order', 1, 1 ); function set_author_for_order( $order_id ) { global $woocommerce; $order = wc_get_order( $order_id ); foreach( $order->get_items() as $item_id => $item_product ){ $product_id = $item_product->get_product_id(); }}` – exspet Aug 23 '18 at 15:11
  • 1
    can you dump the `$item_product` value and see what's in? The product ID may be as a an attribute on this object – Mtxz Aug 23 '18 at 16:00