Hide rates for a specific zip code, province, and country

Shopify Partner
8 0 0

Hello, Can Someone please help me to resolve the error?


here is the link from where I am copying the script.




that is the script I am adding.


# ================================ Customizable Settings ================================
# ================================================================
# Hide Rate(s) for Zip/Province/Country
# If the cart's shipping address country/province/zip match the
# entered settings, the entered rate(s) are hidden.
#   - 'country_code' is a 2-character abbreviation for the
#     applicable country or region
#   - 'province_code' is a list of 2-character abbreviations for
#     the applicable provinces or states
#   - 'zip_code_match_type' determines whether the below strings
#     should be an exact or partial match. Can be:
#       - ':exact' for an exact match
#       - ':partial' for a partial match
#   - 'zip_codes' is a list of strings to identify zip codes
#   - 'rate_match_type' determines whether the below strings
#     should be an exact or partial match. Can be:
#       - ':exact' for an exact match
#       - ':partial' for a partial match
#       - ':all' for all rates
#   - 'rate_names' is a list of strings to identify rates
#     - if using ':all' above, this can be set to 'nil'
# ================================================================
    country_code: "US",
    province_code: "CA",
    zip_code_match_type: :exact,
    zip_codes: ["90210"],
    rate_match_type: :exact,
    rate_names: ["Shipping Rate"],

# ================================ Script Code (do not edit) ================================
# ================================================================
# ZipCodeSelector
# Finds whether the supplied zip code matches any of the entered
# strings.
# ================================================================
class ZipCodeSelector
  def initialize(match_type, zip_codes)
    @comparator = match_type == :exact ? '==' : 'include?'
    @zip_codes = zip_codes.map { |zip_code| zip_code.upcase.strip }

  def match?(zip_code)
    @zip_codes.any? { |zip| zip_code.to_s.upcase.strip.send(@comparator, zip) }

# ================================================================
# RateNameSelector
# Finds whether the supplied rate name matches any of the entered
# names.
# ================================================================
class RateNameSelector
  def initialize(match_type, rate_names)
    @match_type = match_type
    @comparator = match_type == :exact ? '==' : 'include?'
    @rate_names = rate_names&.map { |rate_name| rate_name.downcase.strip }

  def match?(shipping_rate)
    if @match_type == :all
      @rate_names.any? { |name| shipping_rate.name.downcase.send(@comparator, name) }

# ================================================================
# HideRatesForZipProvinceCountryCampaign
# If the cart's shipping address zip/province/country match the
# entered settings, the entered rate(s) are hidden.
# ================================================================
class HideRatesForZipProvinceCountryCampaign
  def initialize(campaigns)
    @campaigns = campaigns

  def run(cart, shipping_rates)
    address = cart.shipping_address

    return if address.nil?

    @campaigns.each do |campaign|
      zip_code_selector = ZipCodeSelector.new(campaign[:zip_code_match_type], campaign[:zip_codes])

      country_match =  address.country_code.upcase.strip == campaign[:country_code].upcase.strip
      province_match = address.province_code.upcase.strip == campaign[:province_code].upcase.strip
      zip_match = zip_code_selector.match?(address.zip)

      next unless country_match && province_match && zip_match

      rate_name_selector = RateNameSelector.new(campaign[:rate_match_type], campaign[:rate_names])

      shipping_rates.delete_if do |shipping_rate|


CAMPAIGNS.each do |campaign|
  campaign.run(Input.cart, Input.shipping_rates)

Output.shipping_rates = Input.shipping_rates

I have follow the step by step instruction

I am attaching screen shot below that is showing error.

Screenshot (79).png

Reply 1 (1)

Shopify Partner
6339 580 1350

Hello @aaqibalighuman ,

Not exactly sure what's going on there I'm not sure of how to reproduce that error.

Checking your code against what's on the docs there are no diffs.

And I get no errors when trying the script.


If that is the unmodified script supplied by the shopify help docs it may be to do the stores region and subsequent address fields.

From the note immediately before that script:


The use of zip_code, province and province_code, and country and country_code is specific to the reg...

So for example if in the United Kingdoms I suspect you may need to use postal_code instead of zip_code.



If that's the case no idea why they'd make that note,  and not try to make the script resilient or provide regional variants.


If you still cannot solve it I'd try first try doing a test checkout to see if the script is in fact working, and clear your browser cache and try again.


If still not resolved I'd the Plus stores MSM.



Similar error posts: https://community.shopify.com/c/forums/searchpage/tab/message?advanced=false&allow_punctuation=false... 

Save time & money ,Ask Questions The Smart Way

Confused? Busy? Get the solution you need paull.newton+shopifyforum@gmail.com

Problem Solved? ✔Accept and Like solutions to help future merchants

Answers powered by coffee Buy Paul a Coffee for more answers or donate to eff.org