Upon checkout I am trying to hide the “Private Shipping” method (ID: “shipmondo:32”) when billing.country is set to “NO” for Norway and (billing.vat) is filled.
I have used the code snippet below, but can not make it work, when including the full condition that also include $vat. However, when running just on $country, it works fine. And if changing to “$vat = WC()->customer->get_billing_postcode();” it also works. However, using the billing.cvr I can not make it work.
The checkout field billing.vat has been set up by manually. Does that mean anything?
What can I do to make it work on both conditions like I am trying below?
With king regards 🙂 Lene
add_filter( 'woocommerce_package_rates', 'shipping_based_on_country_and_vat', 100, 2 );
function shipping_based_on_country_and_vat( $rates, $package ) {
$country = WC()->customer->get_billing_country();
$vat = WC()->customer->get_billing_vat();
$condition = $country == "NO" && $vat != "";
// Loop through shipping rates for current shipping package
foreach ( $rates as $rate_key => $rate ) {
if ( $condition ){
$targeted_rate_id = 'shipmondo:32';
if( $targeted_rate_id === $rate_key ) {
unset($rates[$targeted_rate_id]);
}
}
}
return $rates;
}
Used above code and hoped to see Private Shipping disappear
mail is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.