如何从 woocommerce 挂钩中的订单中获取供应商详细信息 - Dokan

How to get vendor details from order inside woocommerce hooks - Dokan

如何从 woocommerce 挂钩内的订单中获取供应商 info/details。到目前为止,我已经能够像这样从订单中获取标准的 woocommerce 字段:

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;
}

现在我要做的是从该订单中获取 Vendor NameVendor Phone Number 并进行一些 post 处理。

Dokan 有一个辅助功能,可以通过订单获取卖家 ID。以下是从订单中获取供应商用户 ID 的方法:

$seller = dokan_get_seller_id_by_order( $order_id );

现在,如果您正在处理子订单:

        $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;
        }

它已经过测试,可以使用最新的 Dokan 版本 3.x

//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;