I have a script that applies a percentage discount to the price according to a specific tag. How would I be able to use that script with the shopify function?
script just in case:
customer = Input.cart.customer
#if logged in
if customer
if tagged freeitems
if customer.tags.include?(‘freeitems’)
Input.cart.line_items.each do |item|
item.change_line_price(item.line_price * 0.0, message: “”)
end
elsif customer.tags.include?(‘school’)
#each product
Input.cart.line_items.each do |line_item|
product = line_item.variant.product
product.tags.each do |tag|
if tag.include? ‘b2b’
per = tag.split(‘:’)[1].split(‘%’)
percent = per[0].to_i
PERCENTAGE = (100-percent)/100
MESSAGE = per[0] + ‘% off’
line_item.change_line_price(line_item.line_price * PERCENTAGE, message: MESSAGE)
end
end
end
end
else
puts “Something went wrong”
end
Output.cart = Input.cart