如何在Woocommerce中停止收取运费

问题描述 投票:5回答:3

当我将运费51.75添加到Woocommerce时。它将这个变为59.我想要精确的运费58.75。

谁遇到过这个?

php wordpress woocommerce rounding shipping
3个回答
4
投票

转到WooCommerce>设置>常规选项卡,确认'小数位数'是2。

enter image description here


5
投票
/**
 * 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。


3
投票

你应该检查你的主题文件。

导航到主题中的文件,该文件正在调用显示价格的功能。

可能有PHP函数round()

文档:Click here

示例:

在您的主题文件中可能有这样的代码:

<?php echo round($price); ?>

您应该将其更改为:

<?php echo $price; ?>
© www.soinside.com 2019 - 2024. All rights reserved.