Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/236.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将Dokan供应商发货地址分配给Woocommerce中的门店地址_Php_Wordpress_Woocommerce_User Roles_Dokan - Fatal编程技术网

Php 将Dokan供应商发货地址分配给Woocommerce中的门店地址

Php 将Dokan供应商发货地址分配给Woocommerce中的门店地址,php,wordpress,woocommerce,user-roles,dokan,Php,Wordpress,Woocommerce,User Roles,Dokan,我正在为我的wordpress站点使用Dokan和Woocommerce插件 我希望所有供应商将其产品发送到商店地址,而不是客户地址。之后,我想把产品从商店运到他们的地址 但发货地址总是显示给供应商,是客户地址,而不是我的地址。我已经在Dokan禁用了供应商发货,但发货地址仍然是客户地址,而不是我的地址 如何将显示给供应商的发货地址更改为我的店铺地址?我检查了Woocommerce设置,没有找到任何解决方案。我应该更改一些代码还是安装更多插件 非常感谢Dokan供应商的用户角色是“供应商”,因此

我正在为我的wordpress站点使用DokanWoocommerce插件

我希望所有供应商将其产品发送到商店地址,而不是客户地址。之后,我想把产品从商店运到他们的地址

但发货地址总是显示给供应商,是客户地址,而不是我的地址。我已经在Dokan禁用了供应商发货,但发货地址仍然是客户地址,而不是我的地址

如何将显示给供应商的发货地址更改为我的店铺地址?我检查了Woocommerce设置,没有找到任何解决方案。我应该更改一些代码还是安装更多插件


非常感谢

Dokan供应商的用户角色是“供应商”,因此您可以将此用户角色作为目标,并:

  • 在购物车和结帐页面中,将发货地址设置为店铺地址
  • 按订单提交另存为发货地址的店铺基地
守则:

// Utility function that outputs the shop base address in an array
function get_shop_base_address() {
    $country_state = explode( ':', get_option( 'woocommerce_default_country' ) );

    return array(
        'address1'  => get_option( 'woocommerce_store_address' ),
        'address2' => get_option( 'woocommerce_store_address_2' ),
        'city'     => get_option( 'woocommerce_store_city' ),
        'postcode' => get_option( 'woocommerce_store_postcode' ),
        'state'    => $country_state[0],
        'country'  => isset($country_state[1]) ? $country_state[1] : '',
    );
}


// Set vendor shipping address to the shop base in Cart and checkout
add_action( 'template_redirect', 'set_vendor_shipping_address', 10 );
function set_vendor_shipping_address() {
    if( ( is_cart() || ( is_checkout() && ! is_wc_endpoint_url() ) ) &&
    if( current_user_can( 'vendor' ) ) {

        // Get shop base country/state
        $address = get_shop_base_address();

        // Set customer shipping
        WC()->customer->set_shipping_address_1( $address['address1'] );
        WC()->customer->set_shipping_address_2( $address['address2'] );
        WC()->customer->set_shipping_city( $address['city'] );
        WC()->customer->set_shipping_postcode( $address['postcode'] );
        WC()->customer->set_shipping_state( $address['state'] );
        WC()->customer->set_shipping_country( $address['country'] );
    }
}


// Save vendor order shipping address to the shop base
add_action( 'woocommerce_checkout_create_order', 'save_vendor_shipping_address', 10, 2 );
function save_vendor_shipping_address( $order, $data ) {
    if( current_user_can( 'vendor' ) ) {

        // Get shop base country/state
        $address = get_shop_base_address();

        // Set customer shipping
        $order->set_shipping_address_1( $address['address1'] );
        $order->set_shipping_address_2( $address['address2'] );
        $order->set_shipping_city( $address['city'] );
        $order->set_shipping_postcode( $address['postcode'] );
        $order->set_shipping_state( $address['state'] );
        $order->set_shipping_country( $address['country'] );
    }
}

代码进入活动子主题(或活动主题)的function.php文件。测试和工作。

感谢您的解决方案。我确实尝试过压缩这段代码并粘贴到plugins/dokan pro/includes/functions.php中。之后,显示给供应商的发货地址和账单地址是客户输入的地址,而不是商店地址。我还需要做些什么吗?@MJB警告:代码放在主题的function.php文件中。它不在任何现有插件中…禁止覆盖现有Wordpress核心文件或插件核心文件。亲爱的@LoicTheAztec我在theme function.php文件中添加了代码,但没有再次工作。