在产品页

时间:2018-01-24 07:52:36

标签: wordpress woocommerce product tax

我正在使用woocoommerce 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,因为产品总价格正常。

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

任何人都可以帮我解决这个问题。

提前致谢。

1 个答案:

答案 0 :(得分:0)

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

根据建议,您需要从woocommerce中复制活动子主题或主题中的templates文件夹。然后将其重命名为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>
&#13;
&#13;
&#13;

由于附加价格未格式化,您可能需要使用一些woocommerce php函数将其他元素与此附加价格混合:

&#13;
&#13;
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.
&#13;
&#13;
&#13;

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

相关问题