Last active
January 13, 2021 15:39
-
-
Save FrancoStino/70694c531ef6110cc211c5760db93f65 to your computer and use it in GitHub Desktop.
Add extra charge on shipping rate for each KG weight on cart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Add extra charge on shipping rate for each KG weight on cart | |
*/ | |
add_filter( 'woocommerce_package_rates', 'custom_delivery_flat_rate_cost_calculation', 10, 2 ); | |
function custom_delivery_flat_rate_cost_calculation( $rates, $package ) | |
{ | |
// The total cart items weight | |
$cart_weight = WC()->cart->get_cart_contents_weight(); | |
foreach($rates as $rate_key => $rate_values){ | |
$method_id = $rate_values->method_id; | |
$rate_id = $rate_values->id; | |
if ( 'wbs' === $method_id && $cart_weight > 500) { // Se lo slug di spedizione è uguale a, e il peso è maggiore di 500 | |
## SHIPPING COSTS AND TAXES CALCULATIONS ## | |
for( $i = 500; $i < $cart_weight; $i += 1 ){ | |
$rates[$rate_id]->cost += 0.40; | |
} | |
} | |
return $rates; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment