Удалить страну из заказа, но не из корзины - PullRequest
0 голосов
/ 15 марта 2020

Используя следующий скрипт в wocommerce, Швеция будет удалена как из корзины, так и из корзины

function woo_remove_specific_country( $country ) 
{
   unset($country["SE"]);
   return $country; 
}
add_filter( 'woocommerce_countries', 'woo_remove_specific_country', 10, 1 );

Как я могу видеть его так, чтобы он отображался только в корзине при расчете стоимости доставки и не отображался на странице оформления заказа?

С уважением, Мартин

if ( is_checkout() ) { 
function woo_remove_specific_country( $country ) 
{
   unset($country["SE"]);
   return $country; 
}
add_filter( 'woocommerce_countries', 'woo_remove_specific_country', 10, 1 );

 } 

Ничего не происходит, когда я нахожусь на кассе?

Также выполняются следующие действия:

function woo_remove_specific_country( $country ) {
    if ( is_checkout() ) {
       unset($country["SE"]); 
    }
    return $country; 
}
add_filter( 'woocommerce_countries', 'woo_remove_specific_country', 10, 1 );

1 Ответ

0 голосов
/ 15 марта 2020

Это не проверено, так как я никогда не работал с woo commerce - он предлагается просто в качестве предложения ... Надеюсь, вы можете использовать этот крючок.

Ваш add_filter('woocommerce_countres') будет вызываться каждый раз, когда страны появляются на странице. Так что вам нужно быть более точным c в вашем таргетинге.

// Your code to remove the country
function woo_remove_specific_country( $country ) {
    if ( is_checkout() ) {
       unset($country["SE"]); 
    }
    return $country; 
}

// Call the filter function that you already developed... but don't call it every time the countries are shown (see the function call below this function)
function woo_remove_country_filter() {
  add_filter( 'woocommerce_countries', 'woo_remove_specific_country', 10, 1 );
}

// Instead of calling the filter on every page that has "countries", only call it on the checkout form
add_action( 'woocommerce_before_checkout_form', 'woo_remove_country_filter' );
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...