Hide the shipping rate on the draft checkout page

How can I hide the “3rd Party Shipping” shipping rate on the Shopify draft checkout page when the customer doesn’t have the “3party” tag? I’ve tried modifying the shipping rates in the Shopify admin, but there doesn’t seem to be an option to use customer tags as a condition.

Hello @Eugene_wbm

See if this works for you

  1. Go to your Shopify admin and click on “Settings” and then “Shipping and delivery.”

  2. Click on “Manage rates” for the shipping profile you want to edit.

  3. Click on “Edit” next to the shipping rate you want to conditionally hide.

  4. In the “Rate name” field, add the prefix “[hidden]” to the beginning of the name to make the rate invisible.

  5. Click “Save” to save the changes.

  6. Go to “Settings” and then “Checkout” and scroll down to the “Additional scripts” section.

  7. Click on “Manage scripts” to open the script editor.

  8. Click on “Create script” and then select “Shipping” as the script type.

  9. In the script editor, add the following code:

var customer = Checkout.customer || {};
if (customer.tags.indexOf('3party') === -1) {
  var rates = Checkout.shipping_rates;
  for (var i = 0; i < rates.length; i++) {
    if (rates[i].name.indexOf('[hidden]') === 0) {
      rates.splice(i, 1);
      break;
    }
  }
}

This code checks if the customer has the “3party” tag and, if not, removes any shipping rates with the “[hidden]” prefix. Click “Save” to save the script.