Skip to content

Instantly share code, notes, and snippets.

View westondeboer's full-sized avatar

weston deboer westondeboer

View GitHub Profile
@westondeboer
westondeboer / gist:6065b81ba67544ef542d8710e38c1b5f
Created May 21, 2024 20:15
Free Shipping for VIP customers
# Shipping Script to provide free shipping based on customer tags
class FreeShippingScript
def initialize(cart, shipping_rates)
@cart = cart
@shipping_rates = shipping_rates
@customer = cart.customer
end
def run
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