Created
April 24, 2020 05:02
-
-
Save jimmijazz/947b390b1a8150017447760bdcf9e389 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
payment_gateways = ["Afterpay", "BitPay"] # Gateways to hide | |
tag = "lowstock" # Tag to look for | |
lowStockVariantIDS = [] # Will contain variant ID's of low stock items | |
# Loop over line items to check if any have low stock tag. | |
# If product doeshave tag, add it to our lowStockVariantIDs array. | |
Input.cart.line_items.each do |item| | |
#Note: this won't be very efficient for products with lots of tags | |
item.variant.product.tags.each do |tag| | |
tagArray = tag.split(":") # ["variant_title(int", "lowstock"] | |
if (tagArray[1] == "lowstock") | |
unless lowStockVariantIDS.include?(tagArray[0]) | |
lowStockVariantIDS.push(tagArray[0]) | |
end | |
end | |
end | |
end | |
# Loop over variants to see if any match those we found earlier. | |
# Seperate loop as tags are stoed on the product level and we need | |
# to check against variants. | |
Input.cart.line_items.each do |item| | |
if lowStockVariantIDS.include?(item.variant.id.to_s) | |
#Remove gateways listed in payment_gateways | |
Output.payment_gateways = Input.payment_gateways.delete_if do |payment_gateway| | |
# puts payment_gateway.name | |
payment_gateways.include?(payment_gateway.name) | |
end | |
end | |
end | |
Output.payment_gateways = Input.payment_gateways |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment