Woocommerce change the shipping cost related with the subtotal

倖福魔咒の 提交于 2021-02-08 10:00:35

问题


I would like to know how can i change the shipping cost for example:

If subtotal is lower than 10€ then shipping cost is 4.5€ if subtotal is same or higher than 10€ then make the shipping cost 2.5€


回答1:


The right way of doing it is like this:

add_filter( 'woocommerce_package_rates', 'woocommerce_package_rates', 10, 2 );
function woocommerce_package_rates( $rates, $package ) {

    $new_cost = ( WC()->cart->subtotal < 10 ) ? 4.5 : 2.5;

    foreach($rates as $key => $rate ) {
        $rates[$key]->cost = $new_cost;
    }

    return $rates;
}

more about it here.



来源:https://stackoverflow.com/questions/43881390/woocommerce-change-the-shipping-cost-related-with-the-subtotal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!