Trying to exclude Media Mail when a T-shirt is in the cart

Tourist
6 1 0

Looking for some direction here with scripts.  All of our products are eligible for media mail shipping except our t-shirts, so we're trying to remove 'media mail' from the shipping options if a t-shirt is in the cart.

 

I'm not a ruby expert but here is the code so far:

Input.cart.line_items.each do |item|
 if item.sku.upcase.include?("MS-SHIRT") || item.sku.upcase.include?("MS-TS")
  Output.shipping_rates = Input.shipping_rates.delete_if do |shipping_rate|
   shipping_rate.name.upcase.include?("MEDIA MAIL")
  end
 end
end

Output.shipping_rates = Input.shipping_rates

It is throwing this error:

[Error] undefined method 'sku' for #<Variant:0x7f7eb251fa20>
Hide media mail shipping rates:2:in Object.call
shopify/std_lib/core/list.rb:41:in List.each
Hide media mail shipping rates:1

 

sku appears to be correct for line items from the documentation that I've seen.  Any help as to what's wrong with this code would be greatly appreciated.  

0 Likes
Highlighted
Tourist
6 1 0

The answer to this is posted here:

 

https://community.shopify.com/c/Script-Editor/Trying-to-exclude-Media-Mail-when-a-T-shirt-is-in-the-...

 

I didn't realize when I posted this that there was a script editor board that it should've gone into.

0 Likes