Hi!
i tried to filterer the kind of shipping with this code but it´s not working. I just want to show one type of shipping when the user send his product to Ceuta,Melilla, Baleares or Canarias. It should be show “flat_rate” when the subtotal is more than 30 euros. And in the other case, should be show “local_delivery” when the subtotal is less than 30 euros. But with this code in the functions.php of my child theme, it´s not working… ¿What´s the problem? Thanks!
add_filter( ‘woocommerce_package_rates’, ‘ocultar_otros_envios’, 10, 2 );
// Hide other shippings
function ocultar_otros_envios( $rates, $package ) {
$subtotal=substr(wc_cart_totals_subtotal_html(), 0,-1);
$sub=doubleval($subtotal);
$free=30;
if($subtotal < $free){
if ( isset( $rates[‘local_delivery’] ) ){
unset( $rates[‘flat_rate’] );
$local_delivery = $rates[‘local_delivery’];
$rates = array();
$rates[‘local_delivery’] = $local_delivery;
return $rates;
}
}else{
unset( $rates[‘local_delivery’] );
$flat_rate = $rates[‘flat_rate’];
$rates = array();
$rates[‘flat_rate’] = $flat_rate;
return $rates;
}
return $rates;
}