Присвоить адрес доставки Dokan продавцу по адресу магазина в Woocommerce

я использую Докан а также WooCommerce Плагин для моего WordPress сайта.

Я хочу, чтобы все поставщики отправляли свою продукцию по адресу магазина, а не по адресу клиента. После этого я хочу отправить товары из магазина по их адресу.

Но всегда адрес доставки показывается продавцам, это адрес клиента, а не мой адрес. Я отключил доставку поставщика в Dokan, но адрес доставки все еще является адресом клиента, а не моим.

Как я могу изменить адрес доставки, показанный продавцам, на адрес моего магазина? Я проверил настройки Woocommerce и не нашел никакого решения. Должен ли я изменить некоторые коды или установить больше плагинов?

Большое спасибо

1

Решение

Роль пользователя для поставщиков Dokan — это «vendor», поэтому вы можете указать эту роль пользователя и:

  • На страницах корзины и оформления заказа укажите адрес доставки в базе магазина
  • На заказ отправить сохранить как адрес доставки базы магазина

Код:

// 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() ) )
&& 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 вашей активной дочерней темы (или активной темы). Проверено и работает.

1

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector