如何从WooCommerce订单中获得Dokan供应商仓库地址?

长篇版本:

我正在开发一个用于自动托运预订的WordPress/WooCommerce插件,我需要该插件的收件地址,问题是,这是一个使用Dokan插件的多供应商WooCommerce设置,所以我只是想了解如何根据WooCommerce订单获取供应商的仓库地址.

我已经try 了WooCommerce文档,看看他们是否有seller个相关的助手,我已经判断了WooCommerce提供的各种内置类,看看是否有任何方法可以获取卖家的详细信息.

我试着搜索Dokan文档,但他们没有任何具体的文档来帮助我.

推荐答案

在Dokan插件中,没有真正的供应商仓库地址.

您可以通过Order Items从定义的WC_Order对象$order获取供应商详细信息:

// Loop through order "line items"
foreach ( $order->get_items() as $item ) {
    $author_id  = get_post_field( 'post_author', $item->get_product_id() );
    $vendor     = dokan()->vendor->get($author_id);

    $shop_name  = $vendor->get_shop_name();  // <== Shop name
    $first_name = $vendor->get_first_name(); // <== First name
    $last_name  = $vendor->get_first_name(); // <== Last name
    $address    = $vendor->get_address();    // <== Address
    $location   = $vendor->get_location();   // <== Location
    $phone      = $vendor->get_phone();      // <== Phone 
    $email      = $vendor->get_email();      // <== Email 
}

供应商可以定义仓库地址的唯一情况是在启用货到付款发货选项时,可以在"Description"字段中有 Select 地定义仓库地址.看它here in the documentation.

enter image description here

这个仓库地址应该存储在数据库中的Dokan专有表中,就像WooCommerce中的there is NO description field个货到付款发货选项一样.

enter image description here

该仓库地址可以从定义的WC_Order对象$order中的订单中获得(无需任何担保),以"发货"物品:

// Loop through order "line items"
foreach ( $order->get_items('shipping') as $item ) {
    // raw output shipping data
    print_r($item->get_data());

    // raw output shipping meta data
    print_r($item->get_meta_data());
}

我希望这会有帮助.

相关:

Php相关问答推荐

当我们使用PHPUnit时,控制台中的--uses param到底起了什么作用以及如何使用?

Laravel迁移返回SQL错误,但SQL有效且工作正常

累加平面数组中数字子集的所有组合,以生成组合及其乘积的二维数组

LaravelEloquent 的地方条件父/子与第三模型多对多

使用WordPress wp_mail()的邮箱标题无效

在Laravel Eloquent中实现一对多关系

目标类[Set_Locale]不存在.拉威尔

在WooCommerce管理中 for each 运输方法设置添加自定义字段

从AJAX响应中获取一个未定义的html

如何在Livewire 3 Form类中做依赖注入?

基于服务器的不同地平线配置

Shopware 6 插件:如何删除布尔配置并将其迁移到多选配置

WooCommerce 回购自定义插件:如何更新用户钱包?

如何正确判断 PHP 是否已正确配置为使用 DOMDocument?

根据所选付款方式更改 WooCommerce 提交结帐按钮文本

PHP - 计算非数值数组

在WooCommerce中显示 checkout 的高级自定义字段(Advanced Custom Fields)并保存其值

如何通过额外的属性和本地化来使用 laravel 枚举

Laravel 8:会话不适用

如何在供应商名称后将自定义徽章添加到商品详情