I am using WooCommerce for WordPress.
我正在为WordPress使用WooCommerce。
I'm listing items excluding VAT.
我列出了不含增值税的项目。
I need to show Price, VAT and PRICE + VAT separately on the product page (like checkout page).
我需要在产品页面上分别显示价格,VAT, Price + VAT(比如checkout页面)。
I have not been able to find a plugin that does this.
我还没有找到这样的插件。
How can I do this?
我该怎么做呢?
3 个解决方案
#1
11
WooCommerce v3.0.0 and Later
As of WooCommerce version 3.0, the function woocommerce_price() is deprecated, as is the the method get_price_including_tax(). Instead, you should use wc_get_price_including_tax:
WooCommerce v3.0.0和之后的WooCommerce 3.0版本中,已经弃用了woocommerce_price()函数,以及get_price_including_tax()方法。相反,您应该使用wc_get_price_including_tax:
<?php echo wc_price( wc_get_price_including_tax( $product ) ); ?>
Prior to WooCommerce v3.0.0
You need to modify a template. Do not modify the core WooCommerce template, but rather make a copy of it to your theme, using the WooCommerce template override system. For help with that, refer to the WooCommerce docs on using the template override system.
在WooCommerce v3.0.0之前,您需要修改模板。不要修改核心的WooCommerce模板,而是使用WooCommerce模板覆盖系统将其复制到您的主题。要获得帮助,请参考使用模板覆盖系统的WooCommerce文档。
In the price.php
template, you will add this bit of code where you want the price, including tax (VAT):
的价格。php模板,您将在需要价格的地方添加这段代码,包括税金(VAT):
<?php echo woocommerce_price( $product->get_price_including_tax() ); ?>
Note: the price.php
template that you modify should be located here in wp-content/themes/[your theme folder]/woocommerce/single-product/price.php
注意:价格。您需要修改的php模板应该位于wp-content/theme /[您的主题文件夹]/woocommerce/单产品/price.php中
#2
6
At the moment you don't need to change a template anymore. You can set this in the Woocommerce settings:
现在您不需要再更改模板了。你可以在Woocommerce环境中设置:
- Woocommerce: Tax tab: Display Prices in the Shop / Display Prices During Cart and Checkout
- Woocommerce: Tax tab:在购物车和结帐过程中显示价格。
#3
5
Before check that your WooCommerce Tax general settings match with your needs.
在检查你的税务一般设置是否符合你的需要之前。
As cale_b suggested, you need to copy from woocommerce the templates
folder inside your active child theme or theme. Then rename it woocommerce
. In this woocommerce
templates folder you will find inside single-product
subfolder the price.php template to edit related to pricing display in single product pages.
正如cale_b所建议的,您需要从woocommerce中复制活动子主题或主题中的模板文件夹。然后woocommerce重命名。在这个woocommerce模板文件夹中,您将在单产品子文件夹中找到价格。在单个产品页面中编辑与价格显示相关的php模板。
In price.php just after:
在价格。php后:
global $product;
Replace the code with:
将代码替换为:
?>
<div itemprop="offers" itemscope itemtype="http://schema.org/Offer">
<?php
$simple_product_price = $product->get_price_html(); // price without VAT
$simple_product_total = $product->get_price_including_tax(); // price with included VAT
$simple_product_vat = $simple_product_total - $simple_product_price; // VAT price amount
?>
<p class="price"><?php echo $simple_product_price; /* without VAT */ ?></p> (formatted)
<p class="price-vat"><?php echo $simple_product_vat; /* VAT */ ?></p>
<p class="price-and-vat"><?php echo $simple_product_total; /* With VAT */ ?></p>
<meta itemprop="price" content="<?php echo esc_attr( $product->get_price() ); ?>" />
<meta itemprop="priceCurrency" content="<?php echo esc_attr( get_woocommerce_currency() ); ?>" />
<link itemprop="availability" href="http://schema.org/<?php echo $product->is_in_stock() ? 'InStock' : 'OutOfStock'; ?>" />
</div>
Because the additional prices are unformatted, you may need to mix some other elements with this additionals prices using some woocommerce php functions like:
由于附加价格没有格式化,您可能需要使用woocommerce php函数将其他一些元素与附加价格混合,比如:
get_price_suffix( ) // Get the suffix to display after prices > 0.
$currency = esc_attr( get_woocommerce_currency( ) ) // Get the currency code.
get_woocommerce_currency_symbol( $currency ) // Get the currency symbol.
get_tax_class( ) // Returns the tax class.
get_tax_status( ) // Returns the tax status.
Reference: WooCommerce WC_Product class
参考:WooCommerce WC_Product类
#1
11
WooCommerce v3.0.0 and Later
As of WooCommerce version 3.0, the function woocommerce_price() is deprecated, as is the the method get_price_including_tax(). Instead, you should use wc_get_price_including_tax:
WooCommerce v3.0.0和之后的WooCommerce 3.0版本中,已经弃用了woocommerce_price()函数,以及get_price_including_tax()方法。相反,您应该使用wc_get_price_including_tax:
<?php echo wc_price( wc_get_price_including_tax( $product ) ); ?>
Prior to WooCommerce v3.0.0
You need to modify a template. Do not modify the core WooCommerce template, but rather make a copy of it to your theme, using the WooCommerce template override system. For help with that, refer to the WooCommerce docs on using the template override system.
在WooCommerce v3.0.0之前,您需要修改模板。不要修改核心的WooCommerce模板,而是使用WooCommerce模板覆盖系统将其复制到您的主题。要获得帮助,请参考使用模板覆盖系统的WooCommerce文档。
In the price.php
template, you will add this bit of code where you want the price, including tax (VAT):
的价格。php模板,您将在需要价格的地方添加这段代码,包括税金(VAT):
<?php echo woocommerce_price( $product->get_price_including_tax() ); ?>
Note: the price.php
template that you modify should be located here in wp-content/themes/[your theme folder]/woocommerce/single-product/price.php
注意:价格。您需要修改的php模板应该位于wp-content/theme /[您的主题文件夹]/woocommerce/单产品/price.php中
#2
6
At the moment you don't need to change a template anymore. You can set this in the Woocommerce settings:
现在您不需要再更改模板了。你可以在Woocommerce环境中设置:
- Woocommerce: Tax tab: Display Prices in the Shop / Display Prices During Cart and Checkout
- Woocommerce: Tax tab:在购物车和结帐过程中显示价格。
#3
5
Before check that your WooCommerce Tax general settings match with your needs.
在检查你的税务一般设置是否符合你的需要之前。
As cale_b suggested, you need to copy from woocommerce the templates
folder inside your active child theme or theme. Then rename it woocommerce
. In this woocommerce
templates folder you will find inside single-product
subfolder the price.php template to edit related to pricing display in single product pages.
正如cale_b所建议的,您需要从woocommerce中复制活动子主题或主题中的模板文件夹。然后woocommerce重命名。在这个woocommerce模板文件夹中,您将在单产品子文件夹中找到价格。在单个产品页面中编辑与价格显示相关的php模板。
In price.php just after:
在价格。php后:
global $product;
Replace the code with:
将代码替换为:
?>
<div itemprop="offers" itemscope itemtype="http://schema.org/Offer">
<?php
$simple_product_price = $product->get_price_html(); // price without VAT
$simple_product_total = $product->get_price_including_tax(); // price with included VAT
$simple_product_vat = $simple_product_total - $simple_product_price; // VAT price amount
?>
<p class="price"><?php echo $simple_product_price; /* without VAT */ ?></p> (formatted)
<p class="price-vat"><?php echo $simple_product_vat; /* VAT */ ?></p>
<p class="price-and-vat"><?php echo $simple_product_total; /* With VAT */ ?></p>
<meta itemprop="price" content="<?php echo esc_attr( $product->get_price() ); ?>" />
<meta itemprop="priceCurrency" content="<?php echo esc_attr( get_woocommerce_currency() ); ?>" />
<link itemprop="availability" href="http://schema.org/<?php echo $product->is_in_stock() ? 'InStock' : 'OutOfStock'; ?>" />
</div>
Because the additional prices are unformatted, you may need to mix some other elements with this additionals prices using some woocommerce php functions like:
由于附加价格没有格式化,您可能需要使用woocommerce php函数将其他一些元素与附加价格混合,比如:
get_price_suffix( ) // Get the suffix to display after prices > 0.
$currency = esc_attr( get_woocommerce_currency( ) ) // Get the currency code.
get_woocommerce_currency_symbol( $currency ) // Get the currency symbol.
get_tax_class( ) // Returns the tax class.
get_tax_status( ) // Returns the tax status.
Reference: WooCommerce WC_Product class
参考:WooCommerce WC_Product类