Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save westondeboer/6065b81ba67544ef542d8710e38c1b5f to your computer and use it in GitHub Desktop.
Save westondeboer/6065b81ba67544ef542d8710e38c1b5f to your computer and use it in GitHub Desktop.
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
# Replace 'vip' with the tag you want to check
if @customer && customer_has_tag?('vip')
apply_free_shipping
end
end
private
def customer_has_tag?(tag)
@customer.tags.include?(tag)
end
def apply_free_shipping
@shipping_rates.each do |shipping_rate|
shipping_rate.apply_discount(shipping_rate.price, message: "Free shipping for VIP customers")
end
end
end
# Main execution
script = FreeShippingScript.new(Input.cart, Input.shipping_rates)
script.run
Output.shipping_rates = Input.shipping_rates
@westondeboer
Copy link
Author

Free shipping for customers who are tagged with vip

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