Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimmijazz/734fb82e8adcf830a616aa26a3c901e0 to your computer and use it in GitHub Desktop.
Save jimmijazz/734fb82e8adcf830a616aa26a3c901e0 to your computer and use it in GitHub Desktop.
# This script will apply a 100% discount to all shipping methods if the customers who have a tag in the VIP_CUSTOMER_TAG array
# Define the tag that identifies VIP customers.
VIP_CUSTOMER_TAG = ['trade', 'wholesale']
if !Input.cart.customer.nil? # Check there is actually a customer
VIP_CUSTOMER_TAG.each do |tag| # Loop over their tags
if Input.cart.customer.tags.include?(tag.downcase) # Check for upper or lower case
Input.shipping_rates.each do |shipping_rate| # Loop over shipping rates
shipping_rate.apply_discount(shipping_rate.price, message: "Free shipping for Trade and Wholesale Customers!") # Apply discount
end
break
end
end
end
# Export the rates.
Output.shipping_rates = Input.shipping_rates
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment