Custom Woocommerce Shipping Discount

Hello,

I want to modify some standard woocommerce information.

I’m using this code inside a plugin in wordpress to make this change for me, the plugin is called Code Snippets.

After adding the code necessary for me to give a percentage discount for different shipping methods (which is working) I want to add a custom label to each available shipping method name. These methods are from a plugin called Correios for Woocommerce.

I want to put how much discount was given after the method itself. I don’t know how to integrate the two codes without giving an error.

Ex .:
PAC: R$ 22.00
You’ve earned 50% off!

Could someone help me, thank you in advance.

The code:

`<?php
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();

// selecao
if ( 'correios-pac' == $rate->get_method_id() ) {
  $rate->set_cost( $cost * 0.5 ); // 0.5 = 50%
}
if ( 'correios-sedex' == $rate->get_method_id() ) {
  $rate->set_cost( $cost * 0.8 ); // 0.8 = 20%
}

$rates[ $key ] = $rate;

}

return $rates;
}
?>`

I found a code that can select the part of the text I want, but it just removes the text. How would I go about adding a text after its content?
And how would you do to select individually as this code is for all methods.

<?php function ace_hide_shipping_title( $label ) { $pos = strpos( $label, ': ' ); return substr( $label, ++$pos ); } add_filter( 'woocommerce_cart_shipping_method_full_label', 'ace_hide_shipping_title' ); ?>
Sponsor our Newsletter | Privacy Policy | Terms of Service