How Can We Help?
Woocommerce frais d’expédition max
OBJECTIFS
Fixer un montant maximum aux frais d'expédition.
CODE
/**
* 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 = 10.50; // The maximum amount would be $10.50
// 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 );+D'INFOS
Dans Child theme function.php