Ading Surcharges in Woocommerce

I have the below function adding surcharges to shipping

add_filter( 'woocommerce_package_rates',  
add_shipping_percentage_surcharge', 10, 2 );
function add_shipping_percentage_surcharge( $rates, $package ) {
     foreach( $rates as $key => $value ) {
          if( $value->method_id == 'betrs_shipping' ) {
        $rates[ $key ]->cost += $rates[ $key ]->cost * 0.12;
        $rates[ $key ]->cost += $rates[ $key ]->cost * 0.10;
        $rates[ $key ]->cost += $rates[ $key ]->cost * 0.30;
return $rates;

What I need is to only add these charges to one shipping method called “Toll IPEC”. I found code below the lines but when putting it in the function with the if statement its not entering it.

$chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
$chosen_shipping = $chosen_methods[0];
if ($chosen_shipping =='Toll IPEC')

I have placed the shipping method as first method in the shipping zone, I think I need a loop but don’t know how to write it???

Read more here: Ading Surcharges in Woocommerce

Leave a Reply

Your email address will not be published. Required fields are marked *