skip to Main Content

How can I get vendor info/details from an order inside woocommerce hooks. So far I’ve been able to get standard woocommerce fields from the order like so:

add_action('woocommerce_order_status_completed', 'wc_send_complete_notif');
function wc_send_complete_notif( $order_id ) {
    $order = wc_get_order( $order_id );
    $phone = $order->billing_phone;
}

Now what I want to do is get Vendor Name and Vendor Phone Number from that order and do some post processing.

2

Answers


  1. Dokan has a helper function to get the seller id by order. Here’s how to get vendor user ID from an order:

    $seller = dokan_get_seller_id_by_order( $order_id );
    

    Now, in case you are working with sub-orders:

            $sellers = dokan_get_seller_id_by_order( $order_id );
    
            // check has sub order 
            if ( $order->get_meta('has_sub_order') ) {
                foreach ($sellers as $seller) {
                    $seller_info      = get_userdata( $seller );
                    $seller_email     = $seller_info->user_email;
                }
            } else {
                $seller_info      = get_userdata( $sellers );
                $seller_email     = $seller_info->user_email;
            }
    

    It is tested and working with the latest Dokan version 3.x

    Login or Signup to reply.
  2. //If there is a suborder, the relevant method returns 0
    if(!dokan_get_seller_id_by_order( $order_id )):
        //get seller id with sub_orders
        $sub_orders = get_children( array( 'post_parent' => $order_id, 'post_type' => 'shop_order' ) );
        foreach($sub_orders as $sub_order):
            $seller_id[] = dokan_get_seller_id_by_order( $sub_order->ID );
        endforeach;
    else:
        $seller_id =  dokan_get_seller_id_by_order( $order_id );
    endif;
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search