【问题标题】:Maximum shipping cost / woocommerce/最高运费/woocommerce/
【发布时间】:2019-05-13 08:10:19
【问题描述】:

首先,对不起我的英语。

我有一个名为 Big Materials 的运输类,什么时候是 10 欧元固定加 2 欧元每件。我已使用此代码将最高运费设置为 ​​24 欧元。

当我将 8 件放入购物车时,运费为 26 欧元。当我把 9 件装到购物车时,运费是 28 欧元,当我把 10 件装到购物车时,运费是我设置的 24 欧元。

我不知道,问题出在哪里。

是在纳税还是……?

你能帮帮我吗?

谢谢。

/**
 * Function to set a minimum/cap on the shipping rates.
 */
function my_minimum_limit_shipping_rates_function( $rates, $package ) {
    $methods = WC()->shipping()->get_shipping_methods();
    $shipping_limit = 24; // The maximum amount would be $24
    // Loop through all rates
    foreach ( $rates as $rate_id => $rate ) {
        // Check if the rate is higher then a certain amount
        if ( $rate->cost > $shipping_limit ) {
            $rate->cost = $shipping_limit;
            // Recalculate shipping taxes
            if ( $method = $methods[ $rate->get_method_id() ] ) {
                $taxes = WC_Tax::calc_shipping_tax( $rate->cost, WC_Tax::get_shipping_tax_rates() );
                $rate->set_taxes( $method->is_taxable() ? $taxes : array() );
            }
        }
    }
    return $rates;
}
add_filter( 'woocommerce_package_rates', 'my_minimum_limit_shipping_rates_function', 10, 2 );

【问题讨论】:

    标签: wordpress shipping


    【解决方案1】:

    $rate->cost 更改为$rates[$rate_id] 并检查

    /**
     * Function to set a minimum/cap on the shipping rates.
     */
    function my_minimum_limit_shipping_rates_function( $rates, $package ) {
        $methods = WC()->shipping()->get_shipping_methods();
        $shipping_limit = 24; // The maximum amount would be $24
        // Loop through all rates
        foreach ( $rates as $rate_id => $rate ) {
            // Check if the rate is higher then a certain amount
            if ( $rate->cost > $shipping_limit ) {
                $rates[$rate_id]->cost = $shipping_limit;                
            }
        }
        return $rates;
    }
    add_filter( 'woocommerce_package_rates', 'my_minimum_limit_shipping_rates_function', 10, 2 );
    

    【讨论】:

    • 嗨爱丽丝,谢谢你的建议。但还是一样。运费高达 28,8 欧元,超过此限制后又回到 24 欧元。我认为这与税收计算有关。我们有 20% 的税。所以 24 欧元加上 20% 的税是 28,8 欧元。我对代码一无所知,但我认为,这是一种设置不含税运费计算的方法。
    • 我有同样的问题,虽然我使用的代码比你的简单(我将在下面发布以供参考)。我相信你是对的,因为税收计算四舍五入很烦人。 :( 我仍在寻找解决方案。如果我找到了,我会在这里发布。
    • 我刚刚意识到我拥有的代码几乎完全相同,哈哈。再次,如果我找到一个解决方案,我会发布税收四舍五入的解决方案。虽然如果 Automattic 能够正确计算运费税,那就太好了:/
    • 我发现了有关运费税的信息,但不幸的是,该代码对我不起作用,我不知道如何使它起作用。其他人可能有一些意见。 stackoverflow.com/a/44604262/5204226
    • 我在 Woocommerce github 上打开了一个问题。 github.com/woocommerce/woocommerce/issues/23710 随意权衡。与此同时,我不得不取消运费税(在我的国家不合法),但这是准确计算运费的唯一方法:/
    猜你喜欢
    • 2021-04-11
    • 1970-01-01
    • 2014-02-12
    • 2014-02-04
    • 1970-01-01
    • 2020-03-21
    • 2016-11-26
    • 2018-07-14
    • 2021-06-20
    相关资源
    最近更新 更多