Created
April 30, 2024 19:34
-
-
Save westondeboer/f5206ea39390b5264bb9413d60c7ae32 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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