WooCommerce - 显示价格含税产品页面
我正在使用WooCommerce for WordPress。WooCommerce - 显示价格含税产品页面
我在列出不含增值税的物品。
我需要在产品页面上单独显示价格,增值税和价格+增值税(如结账页面)。
我一直没能找到这样做的插件。
我该怎么做?
您需要修改模板。 不要修改核心WooCommerce模板,而是使用WooCommerce模板覆盖系统将它复制到您的主题。有关此方面的帮助,请参阅有关使用的WooCommerce文档。
在price.php
模板,你会在那里你想要的价格,含税(增值税)添加这段代码:
<?php echo woocommerce_price($product->get_price_including_tax()); ?>
注意:您修改应该在这里位于wp-content/themes/[your theme folder]/woocommerce/single-product/price.php
price.php
模板
在检查您的WooCommerce 纳税一般设置匹配您的需求之前。
由于cale_b建议,您需要从woocommerce中复制templates
文件夹内的活动儿童主题或主题。然后将其重命名为woocommerce
。在此woocommerce
模板文件夹中,您可以在single-product
子文件夹中找到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>
由于附加价格是未格式化的,你可能需要这个additionals把一些其他元素价格使用一些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设置中设置这样的:
- Woocommerce:税务选项卡:在店/显示屏价格显示屏价格在车和结算
什么spearealty? –
类型错误:单独 –