• Hello there,

    Anyway to get the vendor user id from an order ?

    Thank you!

    Edit : I see there is the $vendor_id meta in the parent order but how to convert into a user id ?

    [Moderator note: Please, No bumping].

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Giuseppe Madaudo

    (@askmagic)

    Hi there,
    you ca use this:

    $user = $vendor->get_owner();

    Thread Starter arthrnvrn

    (@arthrnvrn)

    Hi there,

    Thank you for the reply.

    Not work, nothing to declare about $vendor like $vendor = yith_get_vendor('current', 'user'); ? This example also not work by the way ??

    Thank you!

    Plugin Support Alessio Torrisi

    (@alessio91)

    Hi there,
    when the plugin create a new suborder, it set the vendor as post author, like in this sample code.

    $vendor          = yith_get_vendor( $vendor_id, 'vendor' );
    			$parent_order_id = $parent_order instanceof WC_Order ? $parent_order->get_id() : 0;
    			$order_data      = apply_filters( 'woocommerce_new_order_data', array(
    					'post_type'     => 'shop_order',
    					'post_title'    => sprintf( __( 'Order – %s', 'yith-woocommerce-product-vendors' ), strftime( _x( '%b %d, %Y @ %I:%M %p', 'Order date parsed by strftime', 'yith-woocommerce-product-vendors' ) ) ),
    					'post_status'   => 'wc-' . apply_filters( 'woocommerce_default_order_status', 'pending' ),
    					'ping_status'   => 'closed',
    					'post_excerpt'  => isset( $posted['order_comments'] ) ? $posted['order_comments'] : '',
    					'post_author'   => $vendor->get_owner(),
    					'post_parent'   => $parent_order_id,
    					'post_password' => uniqid( 'order_' ) // Protects the post just in case
    				)
    			);
    
    $suborder_id        = wp_insert_post( $order_data );

    So, you just need get the post from the order_id and then the post author to obtain the vendor owner.

    Once you have the $user object, you can get the vendor in this way.
    $vendor = yith_get_vendor( $user_id, 'user' );

    I hope be helpful for you.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Get vendor id from order’ is closed to new replies.