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;
}
?>`