Created
July 9, 2019 07:56
-
-
Save jimmijazz/734fb82e8adcf830a616aa26a3c901e0 to your computer and use it in GitHub Desktop.
This file contains 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
# 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