【问题标题】:Show prices including tax on product page在产品页面上显示含税价格
【发布时间】:2018-07-03 04:40:21
【问题描述】:

我使用的是 woocommerce V3.0.9,并启用了税收设置。我将Prices entered with tax 设置为Yes, I will enter prices inclusive of tax,将Display prices in the shop 设置为Including Tax,将Additional tax classes 设置为Reduced Rate Zero Rate

此外,在添加产品时,我添加了含税的产品价格。但是在产品详细信息页面上显示的价格是不含税的。例如,我在添加含税产品时添加了产品价格 135.90,在产品详细信息页面上它显示不含税的价格为 123.55,但它应该显示 135.90,因为我已将设置设置为显示含税价格。

在结帐页面上,我得到产品价格 123.55 + 12.35 税 = 135.90 作为产品总价,效果很好。

但我想在产品详细信息页面上显示含税的实际价格,以便客户在将产品添加到购物车之前知道原始价格。

谁能帮我解决这个问题。

提前致谢。

【问题讨论】:

  • 我检查了系统状态,没有问题。

标签: wordpress woocommerce product tax


【解决方案1】:

在检查您的 WooCommerce 税务常规设置是否符合您的需求之前。

按照建议,您需要从 woocommerce 复制活动子主题或主题中的模板文件夹。然后将其重命名为 woocommerce。在此 woocommerce 模板文件夹中,您将在单一产品子文件夹中找到 price.php 模板,以编辑与单一产品页面中的定价显示相关的内容。

price.php 之后:

global $product;

将代码替换为:

?>
<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>

由于附加价格未格式化,您可能需要使用以下 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.

Woocommerce 参考链接:https://docs.woocommerce.com/wc-apidocs/class-WC_Product.html

【讨论】:

  • 感谢您的回复。我尝试了上面的代码,但我仍然得到不含税的价格,即 123.55
  • 你在哪个文件里改过??
  • price.php 文件.. 我把它放在子主题 > woocommerce > 单一产品中
  • 做一件事。一次,您可以从文件中恢复更改。并点击本文链接-docs.woocommerce.com/document/setting-up-taxes-in-woocommerce....您可以轻松获得解决方案
  • 我尝试根据文章进行设置,但我不明白为什么在产品详细信息页面上没有显示含税价格。我尝试自定义使用过滤器挂钩woocommerce_get_price_html,但在这种情况下,由于产品是可变产品,我得到了多个价格。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-06-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-11-17
  • 2019-12-04
  • 2013-04-08
相关资源
最近更新 更多