Time Quota Exceeded on Plus Script

Hi,

I’m running a shipping restriction script, which does the following:

  1. When customer reaches Shipping Info step: For each product in the order, check if the product tags contain “restricted” tag
    1. If no, proceed without any effect
    2. If yes, check if customer shipping address zip code matches any zip code in an array of ~2400 zip codes listed in the script.
      1. If match is found, then we cannot ship to that shipping address, so disable all shipping methods/rates.
      2. If no match is found, display shipping rates as normal.

In 80%+ of cases, customers are placing orders without any issues and the script does not have any errors.

In around 20% of orders, customers are still placing the order without issue, but there is a TimeQuota Exceeded error in the script error log. If I run debug for that order in the error log, it does not produce any timeout error.

I don’t know how to solve this. We can’t decrease the zipcode list size because we have to check the customer’s zip code against that whole list to find a match.

If anyone can help I would really appreciate it.

Here’s the code:

# GENERATED BY THE SHOPIFY SCRIPT CREATOR APP
class Campaign
  def initialize(condition, *qualifiers)
    @condition = (condition.to_s + '?').to_sym
    @qualifiers = PostCartAmountQualifier ? [] : [] rescue qualifiers.compact
    _item_selector = qualifiers.last unless _item_selector
    qualifiers.compact.each do |qualifier|
      is_multi_select = qualifier.instance_variable_get(:@conditions).is_a?(Array)
      if is_multi_select
        qualifier.instance_variable_get(:@conditions).each do |nested_q|
          @post_amount_qualifier = nested_q if nested_q.is_a?(PostCartAmountQualifier)
          @qualifiers << qualifier
        end
      else
        @post_amount_qualifier = qualifier if qualifier.is_a?(PostCartAmountQualifier)
        @qualifiers << qualifier
      end
    end if @qualifiers.empty?
  end

  def qualifies?(cart)
    return true if @qualifiers.empty?
    @unmodified_line_items = cart.line_items.map do |item|
      new_item = item.dup
      new_item.instance_variables.each do |var|
        val = item.instance_variable_get(var)
        new_item.instance_variable_set(var, val.dup) if val.respond_to?(:dup)
      end
      new_item
    end if @post_amount_qualifier
    @qualifiers.send(@condition) do |qualifier|
      is_selector = false
      if qualifier.is_a?(Selector) || qualifier.instance_variable_get(:@conditions).any? { |q| q.is_a?(Selector) }
        is_selector = true
      end rescue nil
      if is_selector
        raise "Missing line item match type" if _match_type.nil?
        cart.line_items.send(@li_match_type) { |item| qualifier.match?(item) }
      else
        qualifier.match?(cart, _item_selector)
      end
    end
  end

  def run_with_hooks(cart)
    before_run(cart) if respond_to?(:before_run)
    run(cart)
    after_run(cart)
  end

  def after_run(cart)
    .apply_final_discount if  && .respond_to?(:apply_final_discount)
    revert_changes(cart) unless @post_amount_qualifier.nil? || @post_amount_qualifier.match?(cart)
  end

  def revert_changes(cart)
    cart.instance_variable_set(:@line_items, @unmodified_line_items)
  end
end

class ConditionallyHideRates < Campaign
  def initialize(condition, customer_qualifier, cart_qualifier, li_match_type, line_item_qualifier, rate_selector)
    super(condition, customer_qualifier, cart_qualifier, line_item_qualifier)
    _match_type = (li_match_type.to_s + '?').to_sym
    @rate_selector = rate_selector
  end

  def run(rates, cart)
    rates.delete_if { |rate| @rate_selector.match?(rate) } if qualifies?(cart)
  end
end

class Qualifier
  def partial_match(match_type, item_info, possible_matches)
    match_type = (match_type.to_s + '?').to_sym
    if item_info.kind_of?(Array)
      possible_matches.any? do |possibility|
        item_info.any? do |search|
          search.send(match_type, possibility)
        end
      end
    else
      possible_matches.any? do |possibility|
        item_info.send(match_type, possibility)
      end
    end
  end

  def compare_amounts(compare, comparison_type, compare_to)
    case comparison_type
      when :greater_than
        return compare > compare_to
      when :greater_than_or_equal
        return compare >= compare_to
      when :less_than
        return compare < compare_to
      when :less_than_or_equal
        return compare <= compare_to
      when :equal_to
        return compare == compare_to
      else
        raise "Invalid comparison type"
    end
  end
end

class ZipCodeQualifier < Qualifier
  def initialize(match_type, match_condition, zips)
    _condition = match_condition
    @invert = match_type == :does_not
    @zips = zips.map(&:downcase).map {|z| z.gsub(' ', '')}
  end

  def match?(cart, selector = nil)
    return false if cart.shipping_address&.zip.nil?
    zip_code = cart.shipping_address.zip.downcase.gsub(' ', '')
    case _condition
      when :match
        return @invert ^ @zips.include?(zip_code)
      else
        return @invert ^ partial_match(@match_condition, zip_code, @zips)
    end
  end
end

class Selector
  def partial_match(match_type, item_info, possible_matches)
    match_type = (match_type.to_s + '?').to_sym
    if item_info.kind_of?(Array)
      possible_matches.any? do |possibility|
        item_info.any? do |search|
          search.send(match_type, possibility)
        end
      end
    else
      possible_matches.any? do |possibility|
        item_info.send(match_type, possibility)
      end
    end
  end
end

class ProductTagSelector < Selector
  def initialize(match_type, match_condition, tags)
    _condition = match_condition
    @invert = match_type == :does_not
     = tags.map(&:downcase)
  end

  def match?(line_item)
    product_tags = line_item.variant.product.tags.to_a.map(&:downcase)
    case _condition
      when :match
        return @invert ^ ((@tags & product_tags).length > 0)
      else
        return @invert ^ partial_match(@match_condition, product_tags, )
    end
  end
end

class AllRatesSelector
  def match?(rate)
    return true
  end
end

CAMPAIGNS = [
  ConditionallyHideRates.new(
    :all,
    nil,
    ZipCodeQualifier.new(
      :does,
      :match,
      ["34223", "34224", "34229", "34230", "34231", "34232", "34233", "34234", "34235", "34236", "34237", "34238", "34239", "34240", "34241", "34242", "34272", "34274", "34275", "34276", "34277", "34278", "34284", "34285", "34286", "34287", "34288", "34289", "34292", "34293", "34295", "35004", "35005", "35006", "35007", "35010", "35013", "35014", "35016", "35019", "35020", "35022", "35023", "35031", "35032", "35033", "35034", "35035", "35036", "35040", "35042", "35043", "35044", "35045", "35046", "35049", "35051", "35052", "35053", "35054", "35055", "35057", "35058", "35060", "35061", "35062", "35063", "35064", "35068", "35070", "35071", "35072", "35073", "35074", "35077", "35078", "35079", "35080", "35082", "35083", "35085", "35087", "35089", "35091", "35094", "35096", "35097", "35098", "35111", "35112", "35114", "35115", "35116", "35117", "35118", "35119", "35120", "35121", "35124", "35125", "35126", "35127", "35128", "35130", "35131", "35133", "35135", "35136", "35139", "35143", "35146", "35147", "35148", "35149", "35150", "35151", "35160", "35171", "35172", "35173", "35175", "35176", "35178", "35179", "35180", "35183", "35184", "35186", "35187", "35188", "35203", "35204", "35205", "35206", "35207", "35208", "35209", "35210", "35211", "35212", "35213", "35214", "35215", "35216", "35217", "35218", "35221", "35222", "35223", "35224", "35226", "35228", "35229", "35233", "35234", "35235", "35242", "35243", "35244", "35254", "35401", "35404", "35405", "35406", "35441", "35442", "35443", "35444", "35446", "35447", "35452", "35453", "35456", "35457", "35458", "35459", "35460", "35461", "35462", "35463", "35464", "35466", "35469", "35470", "35473", "35474", "35475", "35476", "35477", "35480", "35481", "35490", "35501", "35503", "35504", "35540", "35541", "35542", "35543", "35544", "35545", "35546", "35547", "35548", "35549", "35550", "35552", "35553", "35554", "35555", "35559", "35563", "35564", "35565", "35570", "35571", "35572", "35573", "35574", "35575", "35576", "35577", "35578", "35579", "35580", "35581", "35582", "35584", "35585", "35586", "35587", "35592", "35593", "35594", "35601", "35603", "35610", "35611", "35613", "35614", "35615", "35616", "35618", "35619", "35620", "35621", "35622", "35630", "35633", "35634", "35640", "35643", "35645", "35646", "35647", "35648", "35649", "35650", "35651", "35652", "35653", "35654", "35660", "35661", "35670", "35671", "35672", "35673", "35674", "35677", "35739", "35740", "35741", "35744", "35745", "35746", "35747", "35748", "35749", "35750", "35751", "35752", "35753", "35754", "35755", "35756", "35757", "35758", "35759", "35760", "35761", "35762", "35763", "35764", "35765", "35766", "35767", "35768", "35769", "35771", "35772", "35773", "35774", "35775", "35776", "35801", "35802", "35803", "35805", "35806", "35808", "35810", "35811", "35816", "35824", "35896", "35901", "35903", "35904", "35905", "35906", "35907", "35950", "35951", "35952", "35953", "35954", "35955", "35956", "35957", "35958", "35958", "35960", "35961", "35962", "35963", "35966", "35967", "35968", "35970", "35971", "35972", "35973", "35974", "35975", "35976", "35977", "35978", "35979", "35980", "35981", "35982", "35983", "35984", "35985", "35986", "35987", "35988", "35980", "35990", "36003", "36005", "36006", "36009", "36010", "36013", "36016", "36017", "36020", "36021", "36022", "36023", "36024", "36025", "36026", "36027", "36030", "36031", "36032", "36033", "36034", "36035", "36036", "36037", "36038", "36039", "36040", "36041", "36042", "36043", "36044", "36045", "36046", "36047", "36048", "36049", "36051", "36052", "36053", "36054", "36064", "36066", "36067", "36069", "36071", "36075", "36078", "36079", "36080", "36081", "36082", "36083", "36088", "36089", "36091", "36092", "36093", "36100", "36101", "36102", "36103", "36104", "36105", "36106", "36107", "36108", "36109", "36110", "36111", "36112", "36113", "36115", "36116", "36117", "36201", "36203", "36205", "36206", "36207", "36250", "36251", "36255", "36256", "36258", "36260", "36261", "36262", "36263", "36264", "36265", "36266", "36267", "36268", "36269", "36270", "36271", "36272", "36273", "36274", "36275", "36276", "36277", "36278", "36279", "36280", "36301", "36303", "36305", "36310", "36311", "36312", "36313", "36314", "36315", "36316", "36317", "36318", "36319", "36320", "36321", "36322", "36323", "36330", "36340", "36343", "36344", "36345", "36346", "36350", "36351", "36352", "36353", "36360", "36362", "36370", "36371", "36373", "36374", "36375", "36376", "36401", "36420", "36425", "36426", "36432", "36435", "36436", "36439", "36441", "36442", "36444", "36445", "36446", "36451", "36453", "36454", "36455", "36456", "36460", "36467", "36470", "36471", "36473", "36474", "36475", "36476", "36477", "36480", "36481", "36482", "36483", "36502", "36505", "36507", "36509", "36511", "36512", "36513", "36518", "36521", "36522", "36523", "36524", "36525", "36526", "36527", "36528", "36529", "36530", "36532", "36535", "36538", "36539", "36540", "36541", "36542", "36543", "36544", "36545", "36548", "36549", "36550", "36551", "36553", "36555", "36556", "36558", "36559", "36560", "36561", "36562", "36564", "36567", "36568", "36569", "36571", "36572", "36574", "36575", "36576", "36578", "36579", "36580", "36581", "36582", "36583", "36584", "36585", "36587", "36590", "36602", "36603", "36604", "36605", "36606", "36607", "36608", "36609", "36610", "36611", "36612", "36613", "36615", "36616", "36617", "36618", "36619", "36688", "36693", "36695", "36701", "36703", "36720", "36722", "36723", "36726", "36727", "36728", "36732", "36736", "36738", "36740", "36742", "36744", "36748", "36749", "36750", "36751", "36752", "36753", "36754", "36756", "36758", "36759", "36761", "36763", "36765", "36766", "36767", "36768", "36769", "36773", "36775", "36776", "36782", "36783", "36784", "36785", "36786", "36790", "36792", "36793", "36801", "36804", "36830", "36832", "36849", "36850", "36852", "36853", "36854", "36855", "36856", "36858", "36859", "36860", "36861", "36862", "36863", "36865", "36866", "36867", "36869", "36870", "36871", "36874", "36875", "36877", "36879", "36901", "36904", "36907", "36908", "36910", "36912", "36913", "36915", "36916", "36919", "36921", "36922", "36925", "53001", "53002", "53003", "53004", "53005", "53006", "53007", "53010", "53011", "53012", "53013", "53014", "53015", "53016", "53017", "53018", "53019", "53020", "53021", "53022", "53023", "53024", "53027", "53029", "53031", "53032", "53033", "53034", "53035", "53036", "53037", "53038", "53039", "53040", "53042", "53044", "53045", "53046", "53047", "53048", "53049", "53050", "53051", "53057", "53058", "53059", "53061", "53063", "53065", "53066", "53069", "53070", "53072", "53073", "53074", "53075", "53076", "53078", "53079", "53080", "53081", "53083", "53085", "53086", "53088", "53089", "53090", "53091", "53092", "53093", "53094", "53095", "53097", "53098", "53103", "53104", "53105", "53108", "53110", "53114", "53115", "53118", "53119", "53120", "53121", "53122", "53125", "53126", "53128", "53129", "53130", "53132", "53137", "53139", "53140", "53142", "53143", "53144", "53146", "53147", "53149", "53150", "53151", "53153", "53154", "53156", "53158", "53167", "53168", "53170", "53172", "53177", "53178", "53179", "53181", "53182", "53183", "53184", "53185", "53186", "53188", "53189", "53190", "53191", "53192", "53195", "53202", "53203", "53204", "53205", "53206", "53207", "53208", "53209", "53210", "53211", "53212", "53213", "53214", "53215", "53216", "53217", "53218", "53219", "53220", "53221", "53222", "53223", "53224", "53225", "53226", "53227", "53228", "53233", "53235", "53295", "53402", "53403", "53404", "53405", "53406", "53501", "53502", "53503", "53504", "53505", "53506", "53507", "53508", "53510", "53511", "53515", "53516", "53517", "53518", "53520", "53521", "53522", "53523", "53525", "53526", "53527", "53528", "53529", "53530", "53531", "53532", "53533", "53534", "53536", "53537", "53538", "53540", "53541", "53543", "53544", "53545", "53546", "53549", "53550", "53551", "53553", "53554", "53555", "53556", "53557", "53558", "53559", "53560", "53561", "53562", "53563", "53565", "53566", "53569", "53570", "53571", "53572", "53573", "53574", "53575", "53576", "53577", "53578", "53579", "53580", "53581", "53582", "53583", "53585", "53586", "53587", "53588", "53589", "53590", "53593", "53594", "53597", "53598", "53599", "53702", "53703", "53704", "53705", "53706", "53711", "53713", "53714", "53715", "53716", "53717", "53718", "53719", "53726", "53792", "53801", "53802", "53803", "53804", "53805", "53806", "53807", "53808", "53809", "53810", "53811", "53813", "53816", "53817", "53818", "53820", "53821", "53825", "53826", "53827", "53901", "53910", "53911", "53913", "53916", "53919", "53920", "53922", "53923", "53924", "53925", "53926", "53928", "53929", "53930", "53931", "53932", "53933", "53934", "53935", "53936", "53937", "53939", "53941", "53943", "53944", "53946", "53947", "53948", "53949", "53950", "53951", "53952", "53953", "53954", "53955", "53956", "53959", "53960", "53961", "53963", "53964", "53965", "53968", "53969", "54001", "54002", "54003", "54004", "54005", "54006", "54007", "54009", "54010", "54011", "54013", "54014", "54015", "54016", "54017", "54020", "54021", "54022", "54023", "54024", "54025", "54026", "54027", "54028", "54082", "54101", "54102", "54103", "54104", "54106", "54107", "54110", "54111", "54112", "54113", "54114", "54115", "54119", "54120", "54121", "54123", "54124", "54125", "54126", "54127", "54128", "54129", "54130", "54135", "54136", "54137", "54138", "54139", "54140", "54141", "54143", "54149", "54150", "54151", "54153", "54154", "54155", "54156", "54157", "54159", "54160", "54161", "54162", "54165", "54166", "54169", "54170", "54171", "54173", "54174", "54175", "54177", "54180", "54201", "54202", "54204", "54205", "54207", "54208", "54209", "54210", "54211", "54212", "54213", "54214", "54216", "54217", "54220", "54227", "54228", "54229", "54230", "54232", "54234", "54235", "54241", "54245", "54246", "54247", "54301", "54302", "54303", "54304", "54307", "54311", "54313", "54401", "54403", "54405", "54406", "54407", "54408", "54409", "54410", "54411", "54412", "54413", "54414", "54416", "54417", "54418", "54420", "54421", "54422", "54423", "54424", "54425", "54426", "54427", "54428", "54430", "54433", "54435", "54436", "54437", "54440", "54441", "54442", "54443", "54446", "54447", "54448", "54449", "54450", "54451", "54452", "54454", "54455", "54456", "54457", "54458", "54459", "54460", "54462", "54463", "54465", "54466", "54467", "54469", "54470", "54471", "54473", "54474", "54475", "54476", "54479", "54480", "54481", "54484", "54485", "54486", "54487", "54488", "54489", "54490", "54491", "54493", "54494", "54495", "54498", "54499", "54501", "54511", "54512", "54513", "54514", "54515", "54517", "54519", "54520", "54521", "54524", "54525", "54526", "54527", "54529", "54530", "54531", "54534", "54536", "54537", "54538", "54539", "54540", "54541", "54542", "54545", "54546", "54547", "54548", "54550", "54552", "54554", "54555", "54556", "54557", "54558", "54559", "54560", "54561", "54562", "54563", "54564", "54565", "54566", "54568", "54601", "54603", "54610", "54611", "54612", "54613", "54614", "54615", "54616", "54618", "54619", "54621", "54622", "54623", "54624", "54625", "54626", "54627", "54628", "54629", "54630", "54631", "54632", "54634", "54635", "54636", "54637", "54638", "54639", "54641", "54642", "54643", "54644", "54645", "54646", "54648", "54650", "54651", "54652", "54653", "54654", "54655", "54656", "54657", "54658", "54659", "54660", "54661", "54664", "54665", "54666", "54667", "54669", "54670", "54701", "54703", "54720", "54721", "54722", "54723", "54724", "54725", "54726", "54727", "54728", "54729", "54730", "54731", "54732", "54733", "54734", "54736", "54737", "54738", "54739", "54740", "54741", "54742", "54745", "54746", "54747", "54748", "54749", "54750", "54751", "54754", "54755", "54756", "54757", "54758", "54759", "54760", "54761", "54762", "54763", "54765", "54766", "54767", "54768", "54769", "54770", "54771", "54772", "54773", "54801", "54805", "54806", "54810", "54812", "54813", "54814", "54817", "54819", "54820", "54821", "54822", "54824", "54826", "54827", "54828", "54829", "54830", "54832", "54835", "54836", "54837", "54838", "54839", "54840", "54841", "54842", "54843", "54844", "54845", "54846", "54847", "54848", "54849", "54850", "54853", "54854", "54855", "54856", "54857", "54858", "54859", "54861", "54862", "54864", "54865", "54867", "54868", "54870", "54871", "54872", "54873", "54874", "54875", "54876", "54880", "54888", "54889", "54891", "54893", "54895", "54896", "54901", "54902", "54904", "54909", "54911", "54913", "54914", "54915", "54921", "54922", "54923", "54927", "54928", "54929", "54930", "54931", "54932", "54933", "54934", "54935", "54937", "54940", "54941", "54942", "54943", "54944", "54945", "54946", "54947", "54948", "54949", "54950", "54952", "54956", "54960", "54961", "54962", "54963", "54964", "54965", "54966", "54967", "54968", "54970", "54971", "54974", "54977", "54979", "54980", "54981", "54982", "54983", "54984", "54985", "54986", "71601", "71602", "71603", "71630", "71631", "71635", "71638", "71639", "71640", "71642", "71643", "71644", "71646", "71647", "71651", "71652", "71653", "71654", "71655", "71658", "71659", "71660", "71661", "71662", "71663", "71665", "71666", "71667", "71670", "71671", "71674", "71675", "71676", "71677", "71701", "71711", "71720", "71722", "71724", "71725", "71726", "71730", "71740", "71742", "71743", "71744", "71745", "71747", "71749", "71751", "71752", "71753", "71758", "71759", "71762", "71763", "71764", "71765", "71766", "71770", "71772", "71801", "71820", "71822", "71823", "71825", "71826", "71827", "71832", "71833", "71834", "71835", "71836", "71837", "71838", "71839", "71841", "71842", "71845", "71846", "71847", "71851", "71852", "71853", "71854", "71855", "71857", "71858", "71859", "71860", "71861", "71862", "71865", "71866", "71901", "71909", "71913", "71921", "71922", "71923", "71929", "71933", "71935", "71937", "71940", "71941", "71943", "71944", "71945", "71949", "71950", "71952", "71953", "71956", "71957", "71958", "71959", "71960", "71961", "71962", "71964", "71965", "71968", "71969", "71970", "71971", "71972", "71973", "71998", "71999", "72001", "72002", "72003", "72004", "72005", "72006", "72007", "72010", "72011", "72012", "72013", "72014", "72015", "72016", "72017", "72020", "72021", "72022", "72023", "72024", "72025", "72026", "72027", "72029", "72030", "72031", "72032", "72034", "72035", "72036", "72037", "72038", "72039", "72040", "72041", "72042", "72044", "72045", "72046", "72047", "72048", "72051", "72055", "72057", "72058", "72059", "72060", "72061", "72063", "72064", "72065", "72067", "72068", "72069", "72070", "72072", "72073", "72074", "72076", "72079", "72080", "72081", "72082", "72083", "72084", "72085", "72086", "72087", "72088", "72099", "72101", "72102", "72103", "72104", "72106", "72107", "72108", "72110", "72111", "72112", "72113", "72114", "72116", "72117", "72118", "72119", "72120", "72121", "72122", "72123", "72125", "72126", "72127", "72128", "72129", "72130", "72131", "72132", "72134", "72135", "72136", "72137", "72139", "72140", "72141", "72142", "72143", "72149", "72150", "72152", "72153", "72156", "72157", "72160", "72165", "72166", "72167", "72168", "72169", "72170", "72173", "72175", "72176", "72179", "72181", "72201", "72202", "72204", "72205", "72206", "72207", "72209", "72210", "72211", "72212", "72223", "72227", "72301", "72311", "72315", "72320", "72321", "72322", "72324", "72325", "72326", "72327", "72328", "72329", "72330", "72331", "72332", "72333", "72335", "72338", "72339", "72340", "72341", "72342", "72346", "72347", "72348", "72350", "72351", "72353", "72354", "72355", "72358", "72359", "72360", "72364", "72365", "72366", "72367", "72368", "72370", "72372", "72373", "72374", "72376", "72377", "72379", "72383", "72384", "72386", "72389", "72390", "72392", "72394", "72395", "72396", "72401", "72404", "72410", "72411", "72412", "72413", "72414", "72415", "72416", "72417", "72419", "72421", "72422", "72424", "72425", "72426", "72427", "72428", "72429", "72430", "72431", "72432", "72433", "72434", "72435", "72436", "72437", "72438", "72440", "72441", "72442", "72443", "72444", "72445", "72447", "72449", "72450", "72453", "72454", "72455", "72456", "72457", "72458", "72459", "72460", "72461", "72462", "72464", "72466", "72467", "72469", "72470", "72471", "72472", "72473", "72476", "72478", "72479", "72482", "72501", "72512", "72513", "72515", "72517", "72519", "72520", "72521", "72522", "72523", "72524", "72526", "72527", "72528", "72529", "72530", "72531", "72532", "72533", "72534", "72536", "72537", "72538", "72539", "72540", "72542", "72543", "72544", "72546", "72550", "72553", "72554", "72555", "72556", "72560", "72561", "72562", "72564", "72565", "72566", "72567", "72568", "72569", "72571", "72572", "72573", "72576", "72577", "72578", "72579", "72581", "72583", "72584", "72585", "72587", "72601", "72611", "72616", "72617", "72619", "72623", "72624", "72626", "72628", "72629", "72630", "72631", "72632", "72633", "72634", "72635", "72636", "72638", "72639", "72640", "72641", "72642", "72644", "72645", "72648", "72650", "72651", "72653", "72655", "72658", "72660", "72661", "72662", "72663", "72666", "72668", "72669", "72670", "72672", "72675", "72677", "72679", "72680", "72682", "72683", "72685", "72686", "72687", "72701", "72703", "72704", "72712", "72714", "72715", "72717", "72718", "72719", "72721", "72722", "72727", "72729", "72730", "72732", "72734", "72736", "72738", "72739", "72740", "72742", "72744", "72745", "72747", "72749", "72751", "72752", "72753", "72756", "72758", "72760", "72761", "72762", "72764", "72768", "72769", "72773", "72774", "72776", "72801", "72802", "72821", "72823", "72824", "72826", "72827", "72828", "72830", "72832", "72833", "72834", "72835", "72837", "72838", "72839", "72840", "72841", "72842", "72843", "72845", "72846", "72847", "72851", "72852", "72853", "72854", "72855", "72856", "72857", "72858", "72860", "72863", "72865", "72901", "72903", "72904", "72908", "72916", "72921", "72923", "72926", "72927", "72928", "72930", "72932", "72933", "72934", "72935", "72936", "72937", "72938", "72940", "72941", "72943", "72944", "72945", "72946", "72947", "72948", "72949", "72950", "72951", "72952", "72955", "72956", "72958", "72959", "02802", "02804", "02806", "02807", "02808", "02809", "02812", "02813", "02814", "02815", "02816", "02817", "02818", "02822", "02825", "02826", "02827", "02828", "02830", "02831", "02832", "02833", "02835", "02836", "02837", "02838", "02839", "02840", "02841", "02842", "02852", "02857", "02858", "02859", "02860", "02861", "02863", "02864", "02865", "02871", "02872", "02873", "02874", "02875", "02876", "02878", "02879", "02881", "02882", "02885", "02886", "02888", "02889", "02891", "02892", "02893", "02894", "02895", "02896", "02898", "02903", "02904", "02905", "02906", "02907", "02908", "02909", "02910", "02911", "02912", "02914", "02915", "02916", "02917", "02919", "02920", "02921", "05001", "05031", "05032", "05033", "05034", "05035", "05036", "05037", "05038", "05039", "05040", "05041", "05042", "05043", "05045", "05046", "05048", "05050", "05051", "05052", "05053", "05055", "05056", "05058", "05059", "05060", "05061", "05062", "05065", "05067", "05068", "05069", "05070", "05071", "05072", "05075", "05076", "05077", "05079", "05081", "05083", "05084", "05086", "05089", "05091", "05101", "05141", "05142", "05143", "05146", "05148", "05149", "05150", "05151", "05152", "05153", "05154", "05155", "05156", "05158", "05161", "05201", "05250", "05251", "05252", "05253", "05254", "05255", "05257", "05260", "05261", "05262", "05301", "05340", "05341", "05342", "05343", "05345", "05346", "05350", "05352", "05353", "05354", "05355", "05356", "05358", "05359", "05360", "05361", "05362", "05363", "05401", "05403", "05404", "05405", "05439", "05440", "05441", "05442", "05443", "05444", "05445", "05446", "05447", "05448", "05450", "05452", "05454", "05455", "05456", "05457", "05458", "05459", "05461", "05462", "05463", "05464", "05465", "05468", "05471", "05472", "05473", "05474", "05476", "05477", "05478", "05481", "05482", "05483", "05485", "05486", "05487", "05488", "05489", "05491", "05492", "05494", "05495", "05602", "05640", "05641", "05647", "05648", "05649", "05650", "05651", "05652", "05653", "05654", "05655", "05656", "05657", "05658", "05660", "05661", "05663", "05664", "05667", "05669", "05672", "05673", "05674", "05675", "05676", "05677", "05678", "05679", "05680", "05681", "05682", "05701", "05730", "05732", "05733", "05734", "05735", "05736", "05737", "05738", "05739", "05740", "05742", "05743", "05744", "05747", "05748", "05751", "05753", "05757", "05758", "05759", "05760", "05761", "05762", "05763", "05764", "05765", "05766", "05767", "05769", "05770", "05772", "05773", "05774", "05775", "05776", "05777", "05778", "05819", "05820", "05821", "05822", "05824", "05825", "05826", "05827", "05828", "05829", "05830", "05832", "05833", "05836", "05837", "05839", "05841", "05842", "05843", "05845", "05846", "05847", "05850", "05851", "05853", "05855", "05857", "05858", "05859", "05860", "05862", "05866", "05867", "05868", "05871", "05872", "05873", "05874", "05875", "05901", "05902", "05903", "05904", "05905", "05906", "05907", "92101", "92102", "92103", "92104", "92105", "92106", "92107", "92108", "92109", "92110", "92111", "92112", "92113", "92114", "92115", "92116", "92117", "92118", "92119", "92120", "92121", "92122", "92123", "92124", "92126", "92127", "92128", "92129", "92130", "92131", "92132", "92134", "92135", "92136", "92137", "92138", "92139", "92140", "92142", "92143", "92145", "92147", "92149", "92150", "92152", "92153", "92154", "92155", "92158", "92159", "92160", "92161", "92163", "92165", "92166", "92167", "92168", "92169", "92170", "92171", "92172", "92173", "92174", "92175", "92176", "92177", "92178", "92179", "92182", "92186", "92187", "92191", "92192", "92193", "92195", "92196", "92197", "92198", "92199"]
    ),
    :any,
    ProductTagSelector.new(
      :does,
      :include,
      ["restricted"]
    ),
    AllRatesSelector.new()
  )
].freeze

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

Output.shipping_rates = Input.shipping_rates

Two options…

  1. As your zip codes are numeric, rather then comparing each zip code, number comparison like zipCode < 3000 and zipCode > 4000. That will save few loops

  2. Write real time rate app to return special rate when cart have restricted itesm and check in script if special rate then restricted check out.

Thank you Rakesh - the zipCode < 3000, zipCode > 4000 example suggestion is so simple but would save so much processing time. Thank you