Discounted shipping rule according to region

guizo33

New member
XNullUser
Joined
Oct 6, 2021
Messages
1
Reaction score
0
Points
1
NullCash
4
Snippet to add discount on shipping in WordPress.

/* Add code in your plugin "Snnipet".
add_filter( 'woocommerce_package_rates', 'fa_woocommerce_package_rates', 10, 2 );

function fa_woocommerce_package_rates( $rates, $package ) {

foreach ( $rates as $key => $rate ) {
$cost = $rate->get_cost();

// correios-pac is my method_id,

// checking the shipping id
if ( 'correios-pac' == $rate->get_method_id() ) {
$id = $rate->get_instance_id();
if ( 15 == $id || 17 == $id || 19 == $id || 21 == $id ){
$rate->set_cost( $cost * 0 ); // free shipping
}
else if( 13 == $id ){
$rate->set_cost( $cost * 0.5 ); // 0.5 = 50% discount
}
else if( 27 == $id ){
$rate->set_cost(( $cost * 67.7 ) / 100); // 15% discount
}
}

$rates[ $key ] = $rate;
}

return $rates;
}

After add to code in your plugin Snippet in WordPress, your shipping_method update cost for 0 (free shipping) - first condition , 50% discount - second condition, 30% discount -- third condition
 

Attachments

  • Screenshot_42323.png
    Screenshot_42323.png
    38.2 KB · Views: 0

Yee5300

Active member
XNullUser
Joined
Jan 10, 2022
Messages
2,475
Reaction score
0
Points
36
NullCash
12,278
Thank you
Post automatically merged:

Thank you
 
Last edited:
Top