【问题标题】:woocommerce should show same price for eu but net worth for other countrieswoocommerce 应显示欧盟的相同价格,但其他国家/地区的净值
【发布时间】:2021-08-10 09:56:43
【问题描述】:

我这两天一直在寻找解决方案,但很遗憾我找不到。 Woocommerce 应该向欧盟公民显示相同的总价格,包括通常的国家税。但是,对于欧盟以外的第三国,应显示不含税的净价格。

因此,如果我一般使用过滤器add_filter( 'woocommerce_adjust_non_base_location_prices', '__return_false');,它在欧盟内有效,在欧盟以外则显示总价。

所以我想我首先尝试在结帐中确定国家,然后通过 functions.php 过滤器被激活或停用:

add_action( 'woocommerce_cart_calculate_fees', 'same_price_for_eu' );
function same_price_for_eu(){

   $countries = new WC_Countries();
  
   $eu_countries = $countries->get_european_union_countries();

   $billing_country = get_option( 'billing_country' );
   $shipping_country = get_option( 'shipping_country' );

   if ( in_array( $shipping_country, $eu_countries ) ) {
  add_filter( 'woocommerce_adjust_non_base_location_prices', '__return_false');
    
   } else {
   remove_filter( 'woocommerce_adjust_non_base_location_prices', '__return_false');
     
   }
}

你当然可以帮助我,因为我不知道我在做什么:-)


编辑:可以解决它!
add_action( 'woocommerce_cart_calculate_fees', 'same_price_for_eu' );
function same_price_for_eu(){

   $countries = new WC_Countries();
  
   $eu_countries = $countries->get_european_union_countries();

   if ( in_array( WC()->customer->get_shipping_country(), $eu_countries) ){
  add_filter( 'woocommerce_adjust_non_base_location_prices', '__return_false');
    
   } else {
   remove_filter( 'woocommerce_adjust_non_base_location_prices', '__return_false');
     
   }
}

【问题讨论】:

    标签: php woocommerce filter


    【解决方案1】:

    您的解决方案几乎是正确的。税收计算仍然关闭。我检查了购物车,在更改国家/地区时税收计算错误。但是由于您的努力,我创建了这个正确的工作解决方案:

    /**
     * @param $bool
     * @return bool
     */
    function so67632352_woocommerce_adjust_non_base_location_prices($bool): bool
    {
        $countries = new WC_Countries();
        $eu_countries = $countries->get_european_union_countries();
    
        if (WC()->customer && in_array(WC()->customer->get_shipping_country(), $eu_countries)) {
            $bool = false;
        }
    
        return $bool;
    }
    
    add_filter('woocommerce_adjust_non_base_location_prices', 'so67632352_woocommerce_adjust_non_base_location_prices');
    

    【讨论】:

      猜你喜欢
      • 2013-04-30
      • 2018-11-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-19
      • 1970-01-01
      • 2015-09-30
      • 1970-01-01
      相关资源
      最近更新 更多