Skip to content
Advertisement

Disable only specific flat rate shipping method when free shipping is available in WooCommerce

I have two flat rates on my WooCommerce site and I want to disable one of them, when free shipping is enabled. I have a function which is working for all flat rates only.

How do I check for an instance id on a shipping rate? Can anyone help me understand how to check for the instance id?

I Was trying to echo shipping data out to make sense of what values were available but no echo was showing on the front end either so a tip on why would be great.

Here is my code attempt:

JavaScript

Advertisement

Answer

If you inspect the shipping methods radio buttons on cart or in checkout you will see something like:

JavaScript

So in value="flat_rate:20" (which is the rate Id):

  • the method Id is flat_rate,
  • and instance ID is 20.

Note: The code could be really simplified…

But as you don’t provide the free shipping and other flat rate rates IDs (or instances Ids), I Keep your code making some changes to it, this way:

JavaScript

It should work.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement