我如何停止在Woocommerce中调整运费

Roh*_*tam 5 php wordpress rounding shipping woocommerce

当我向Woocommerce添加58.75运费时。将其四舍五入为59。我想要确切的运费58.75。

有人遇到过这个吗?

Sag*_*ang 5

转到 WooCommerce > 设置 > 常规选项卡并确认“小数位数”为 2。

在此处输入图片说明


muj*_*nly 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;
}
Run Code Online (Sandbox Code Playgroud)

请检查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。