首页 > 解决方案 > Woocommerce 在单个产品页面中显示含增值税和不含增值税的价格?

问题描述

我有一个自己无法找到答案的问题。我想在产品价格旁边显示单个产品页面(在我的情况下,目前显示没有增值税),但我想显示没有增值税和增值税,这样我的客户就可以知道他们真正支付的费用。我在 stackoverflow 中搜索了 asnwer,但没有找到有关该主题的正确答案。谁能给我点从哪里开始。我使用 Woo 3.3.5。我在谷歌上找到了这段代码,但它似乎无法正常工作:

function edit_price_display() {
$product = new WC_Product( get_the_ID() );
$price = $product->price;

$price_incl_tax = $price + round($price * ( 21 / 100 ), 2);

$price_incl_tax = number_format($price_incl_tax, 2, ",", "."); 
$price = number_format($price, 2, ",", "."); 

$display_price = '<span class="price">';
$display_price .= '<span class="amount">€ ' . $price_incl_tax .'<small 
 class="woocommerce-price-suffix"> incl BTW</small></span>';
$display_price .= '<br>';
 class="woocommerce-price-suffix"> excl BTW</small></span>';
$display_price .= '</span>';

echo $display_price;
}

 add_filter('woocommerce_price_html', 'edit_price_display');

标签: phpwordpressfunctionwoocommerce

解决方案


推荐阅读