我怎样才能停止在 Woocommerce 中四舍五入运费
How can I stop rounding off shipping charge in Woocommerce
当我向 Woocommerce 添加运费 58.75 时。将其四舍五入为 59。
我要准确的运费 58.75。
有人遇到过这种情况吗?
转到 WooCommerce > 设置 > 常规选项卡并确认 'Number of decimals' 为 2。
你应该检查你的主题文件。
导航到您主题中的文件,该文件正在调用显示价格的函数。
可能有 PHP 函数 round()
文档:Click here
示例:
在你的主题文件中可能有这样的代码:
<?php echo round($price); ?>
您应该将其更改为:
<?php echo $price; ?>
/**
* Get rounding precision for internal WC calculations.
* Will increase the precision of wc_get_price_decimals by 2 decimals, unless WC_ROUNDING_PRECISION is set to a higher number.
*
* @since 2.6.3
* @return int
*/
function wc_get_rounding_precision() {
$precision = wc_get_price_decimals() + 2;
if ( absint( WC_ROUNDING_PRECISION ) > $precision ) {
$precision = absint( WC_ROUNDING_PRECISION );
}
return $precision;
}
请检查 WC_ROUNDING_PRECISION 是否已在其他地方设置(可能在主题中)
您可以设置以下常量来改变舍入计算:https://github.com/woocommerce/woocommerce/blob/master/includes/class-woocommerce.php#L207-L209。我相信它们会在您的 wp-config 文件中更早定义以进行更改。
从这里可以看出,WC 大多会使用较高者:https://github.com/woocommerce/woocommerce/blob/64bcabf0af9a05274d53ec833a4e8c9153509bc4/includes/wc-core-functions.php#L1549-L1553。 WC_ROUNDING_PRECISION 常量,或者您设置的小数位数加 2。
当我向 Woocommerce 添加运费 58.75 时。将其四舍五入为 59。 我要准确的运费 58.75。
有人遇到过这种情况吗?
转到 WooCommerce > 设置 > 常规选项卡并确认 'Number of decimals' 为 2。
你应该检查你的主题文件。
导航到您主题中的文件,该文件正在调用显示价格的函数。
可能有 PHP 函数 round()
文档:Click here
示例:
在你的主题文件中可能有这样的代码:
<?php echo round($price); ?>
您应该将其更改为:
<?php echo $price; ?>
/**
* Get rounding precision for internal WC calculations.
* Will increase the precision of wc_get_price_decimals by 2 decimals, unless WC_ROUNDING_PRECISION is set to a higher number.
*
* @since 2.6.3
* @return int
*/
function wc_get_rounding_precision() {
$precision = wc_get_price_decimals() + 2;
if ( absint( WC_ROUNDING_PRECISION ) > $precision ) {
$precision = absint( WC_ROUNDING_PRECISION );
}
return $precision;
}
请检查 WC_ROUNDING_PRECISION 是否已在其他地方设置(可能在主题中)
您可以设置以下常量来改变舍入计算:https://github.com/woocommerce/woocommerce/blob/master/includes/class-woocommerce.php#L207-L209。我相信它们会在您的 wp-config 文件中更早定义以进行更改。
从这里可以看出,WC 大多会使用较高者:https://github.com/woocommerce/woocommerce/blob/64bcabf0af9a05274d53ec833a4e8c9153509bc4/includes/wc-core-functions.php#L1549-L1553。 WC_ROUNDING_PRECISION 常量,或者您设置的小数位数加 2。