问题
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