• Hi,
    I am trying to get the vendor id from an order id.
    What I was doing to get it mentioned below.

    $order = wc_get_order(5537);
    $product_id   = $order['product_id'];
    $post_obj    = get_post( $product_id );
    $vendor_id = $post_obj->post_author;
    echo $vendor_id;

    It’s print out 1 not actual vendor id.

    How to get actual vendor id?

    Thanks
    Shamir

    • This topic was modified 4 years, 6 months ago by Shamir.
Viewing 1 replies (of 1 total)
  • Plugin Author WC Lovers

    (@wclovers)

    Use this snippet to get all vendors list for an order –

    $processed_vendors = array();
    				if( function_exists( 'wcfm_get_vendor_store_by_post' ) ) {
    					$order = wc_get_order( $order_id );
    					if( is_a( $order , 'WC_Order' ) ) {
    						$items = $order->get_items( 'line_item' );
    						if( !empty( $items ) ) {
    							foreach( $items as $order_item_id => $item ) {
    								$line_item = new WC_Order_Item_Product( $item );
    								$product  = $line_item->get_product();
    								$product_id = $line_item->get_product_id();
    								$vendor_id  = wcfm_get_vendor_id_by_post( $product_id );
    								
    								if( !$vendor_id ) continue;
    								if( in_array( $vendor_id, $processed_vendors ) ) continue;
    								
    								$store_name = wcfm_get_vendor_store( $vendor_id );
    								if( $store_name ) {
    											$processed_vendors[$vendor_id] = $vendor_id;
    								}
    							}
    						}
    					}
    				}
Viewing 1 replies (of 1 total)
  • The topic ‘How to get vendor id from order id?’ is closed to new replies.