我对 woo price.php
有几个问题
首先我喜欢改变方式get_price_html()
显示价格,我找不到办法,然后我决定更改price.php
文件并在 get_price_html
之前添加以下行:
<div class="row">
<div class="col-md-6">
<p class="<?php echo esc_attr( apply_filters( 'woocommerce_product_price_class', 'price' ) ); ?>" style="color: #212529; font-weight: 700; font-size: 1.61rem; line-height: 2rem; text-transform: none; margin-top: -0.25rem;"><?php
echo get_woocommerce_currency_symbol();
echo $product->get_regular_price(); ?></p>
</div>
<div class="col-md-6">
<span class="text-danger">VAT included </span>
</div>
</div>
<div class="row">
<div class="col-md-6">
<p class="<?php echo esc_attr( apply_filters( 'woocommerce_product_price_class', 'price' ) ); ?>" style="color: #212529; font-weight: 700; font-size: 1.61rem; line-height: 2rem; text-transform: none; margin-top: -0.25rem;"><?php
echo get_woocommerce_currency_symbol();
echo $product->get_sale_price();
?></p>
</div>
<div class="col-md-6">
<span class="text-danger">Price per KG </span>
</div>
</div>
它对我有用,并以我正在寻找的风格显示产品的价格。但有几个问题:
- 正如您在
get_price_html
中看到的那样价格显示为,
但在get_regular_price
价格显示为.
作为小数 - 同时
get_sale_price
可用,但不添加<strike>
恢复正常价格。
完全是编辑get_price_html
的好方法。而不是get_sale_price
和get_sale_price
最佳答案
以下重新审视的代码将使用 WooCommerce wc_price()
专用价格格式化函数(还处理货币符号显示)来解决小数分隔符问题。 p>
它也将处理敲定的正常价格。
<div class="row">
<div class="col-md-6">
<p class="<?php echo esc_attr( apply_filters( 'woocommerce_product_price_class', 'price' ) ); ?>" style="color: #212529; font-weight: 700; font-size: 1.61rem; line-height: 2rem; text-transform: none; margin-top: -0.25rem;"><del><?php
echo wc_price(wc_get_price_to_display($product, array('price' => $product->get_regular_price())));
?></del></p>
</div>
<div class="col-md-6">
<span class="text-danger"><?php _e("VAT included"); ?> </span>
</div>
</div>
<div class="row">
<div class="col-md-6">
<p class="<?php echo esc_attr( apply_filters( 'woocommerce_product_price_class', 'price' ) ); ?>" style="color: #212529; font-weight: 700; font-size: 1.61rem; line-height: 2rem; text-transform: none; margin-top: -0.25rem;"><ins><?php
echo wc_price(wc_get_price_to_display($product, array('price' => $product->get_sale_price())));
?></ins></p>
</div>
<div class="col-md-6">
<span class="text-danger"><?php _e("Price per KG"); ?></span>
</div>
</div>
应该会更好。
关于php - WooCommerce 自定义模板price.php 上的小数分隔符问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66109509/