php - Woocommerce 从含税的产品价格中舍入和修剪小数。不含税的价格保持小数
问题描述
对于我们在 Woocommerce 上运行的 eshop,我需要更改计算价格的方式。
目前我正在使用一个代码片段,它将在含税价格的后面显示不含税的价格。片段在这里:
add_filter('woocommerce_get_price_suffix', function ( $html, $product, $price, $qty ) {
if ( ! $html && $product instanceof WC_Product_Variable) {
if ( ( $suffix = get_option( 'woocommerce_price_display_suffix' ) )
&& wc_tax_enabled()
&& 'taxable' === $product->get_tax_status()
) {
$replacements = array(
'{price_including_tax}' => wc_price( wc_get_price_including_tax( $product, array( 'qty' => $qty, 'price' => $price ) ) ),
'{price_excluding_tax}' => wc_price( wc_get_price_excluding_tax( $product, array( 'qty' => $qty, 'price' => $price ) ) ),
);
$html = str_replace( array_keys( $replacements ), array_values( $replacements ), ' <small class="woocommerce-price-suffix">' . wp_kses_post( $suffix ) . '</small>' );
}
}
return $html;
}, 10, 4);
多亏了这个片段,我的价格看起来像这样:
但是有时我需要在我们的 eshop 上批量编辑许多产品,例如将所有夹克的价格提高 2.5%。但是,如果我这样做,价格为 100、00 的产品现在将花费 102、50。我不希望包含税的价格包含任何小数,所以如果有人要更改价格,我需要将其四舍五入并去掉小数,但是只有这个价格含税!如果我Woocommerce > Settings > General
在这里删除小数点,它也会从不含税的价格中删除小数点,这对我们来说是一个大问题,因为四舍五入的税收不是最聪明的主意。
有没有办法强制仅在不含税的价格上显示小数,并在含税的情况下去掉小数和四舍五入?
解决方案
推荐阅读
- javascript - 如何使用标题 attr-Javascript/CSS 为工具提示添加 css 样式和数据放置属性 =“top”
- docker - FFmpeg 流在一定时间后停止
- java - 容器化 WebLogic 服务器中的调试端口
- javascript - React Native State 在不应该更新的时候更新
- flutter - 如何在 Chrome 上调试 Flutter 应用程序并让 Android Studio 在断点处停止?
- c# - 用逗号分割字符串,但忽略单引号和内部单引号内的逗号
- django - 我如何为每个用户分配一个特定链接,通过该链接我可以访问他的个人资料
- r - $multiply 函数在 R studio 中不起作用
- git - 克隆时如何检查 git 子模块更新状态
- distributed - 计划使用 Jaeger 进行分布式跟踪