简体   繁体   English

woocommerce 应该显示欧盟相同的价格,但其他国家/地区的净值

[英]woocommerce should show same price for eu but net worth for other countries

I've been looking for a solution for two days and unfortunately I can't find it.我一直在寻找两天的解决方案,不幸的是我找不到它。 Woocommerce is supposed to display the same gross price for EU citizens including the usual national tax. Woocommerce 应该为欧盟公民显示相同的总价格,包括通常的国家税。 For third countries outside the EU, however, the net price without tax should be displayed.但是,对于欧盟以外的第三国,应显示不含税的净价格。

So if I use the filter add_filter( 'woocommerce_adjust_non_base_location_prices', '__return_false');所以如果我使用过滤器add_filter( 'woocommerce_adjust_non_base_location_prices', '__return_false'); in general, it works within the EU, outside it shows the gross price.一般来说,它在欧盟内部有效,在欧盟外部显示总价格。

So I thought I'd first try to determine the country in the checkout and via functions.php the filter is either activated or deactivated:所以我想我首先尝试在结帐时通过函数确定国家/地区。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');
     
   }
}

Surely you can help me, as I have no idea what I'm doing:-)当然你可以帮助我,因为我不知道我在做什么:-)


Edit: Could solve it! 编辑:可以解决它!
 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'); } }

your solution is almost correct aka.您的解决方案几乎是正确的。 the tax calculation was still off.税收计算仍然关闭。 i checked the cart, when changing the country the tax calculation was wrong.我检查了购物车,在更改国家/地区时税收计算错误。 but thanks to your efforts i created this proper working solution:但是由于您的努力,我创建了这个正确的工作解决方案:

add_action('woocommerce_adjust_non_base_location_prices', 'so67632352_woocommerce_adjust_non_base_location_prices');

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

    if (in_array(WC()->customer->get_shipping_country(), $eu_countries)) {
        return false;
    } else {
        return true;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM