Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save westondeboer/f5206ea39390b5264bb9413d60c7ae32 to your computer and use it in GitHub Desktop.
Save westondeboer/f5206ea39390b5264bb9413d60c7ae32 to your computer and use it in GitHub Desktop.
Input.cart.line_items.each do |line_item|
product = line_item.variant.product
max_qty_tag = product.tags.find { |tag| tag.start_with?('max_') }
if max_qty_tag
max_qty = max_qty_tag.gsub('max_', '').to_i
reduce_by = line_item.quantity - max_qty
line_item.split(take: reduce_by) if reduce_by > 0
end
end
Output.cart = Input.cart
@westondeboer
Copy link
Author

Shopify Code Editor Script
checks product tags for max_1, max_2, max_3 ... etc and only allowed that item to be purchased that many times 1, 2, 3 etc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment