Skip to content

Instantly share code, notes, and snippets.

View dylanjhunt's full-sized avatar

Dylan Hunt dylanjhunt

View GitHub Profile
@dylanjhunt
dylanjhunt / Shopify Scripts - Buy 2 get 1 free
Last active October 26, 2018 08:03
Buy 2 get 1 free Shopify Script. More similar scripts to be downloaded here: https://liquidandscripts.com/collections/free-shopify-scripts
PAID_ITEM_COUNT = 2
DISCOUNTED_ITEM_COUNT = 1
# Returns the integer amount of items that must be discounted next
# given the amount of items seen
#
def discounted_items_to_find(total_items_seen, discounted_items_seen)
Integer(total_items_seen / (PAID_ITEM_COUNT + DISCOUNTED_ITEM_COUNT) * DISCOUNTED_ITEM_COUNT) - discounted_items_seen
end
DISCOUNTS_BY_QUANTITY = {
10_000 => 20,
1_000 => 15,
100 => 10,
10 => 5,
}
Input.cart.line_items.each do |line_item|
next if line_item.variant.product.gift_card?
DISCOUNTS_BY_QUANTITY = {
10_000 => 20,
1_000 => 15,
100 => 10,
10 => 5,
}
Input.cart.line_items.each do |line_item|
next if line_item.variant.product.gift_card?
@percent = Decimal.new(25) / 100.0
Input.cart.line_items.each do |line_item|
product = line_item.variant.product
next if product.gift_card?
next unless product.tags.include?('myTag')
line_discount = line_item.line_price * @percent
line_item.change_line_price(line_item.line_price - line_discount, message: "25% Off")
end
Output.cart = Input.cart
Input.cart.line_items.each do |line_item|
product = line_item.variant.product
next if product.gift_card?
next unless product.tags.include?('MyTag')
line_item.change_line_price(line_item.line_price - Money.new(cents: 500), message: "$5 Off")
end
Output.cart = Input.cart
PAID_ITEM_COUNT = 1
DISCOUNTED_ITEM_COUNT = 1
# Returns the integer amount of items that must be discounted next
# given the amount of items seen
#
def discounted_items_to_find(total_items_seen, discounted_items_seen)
Integer(total_items_seen / (PAID_ITEM_COUNT + DISCOUNTED_ITEM_COUNT) * DISCOUNTED_ITEM_COUNT) - discounted_items_seen
end
@dylanjhunt
dylanjhunt / Shopify Script - X% off if customer placed more than Y orders
Last active April 11, 2017 16:45
Since we cannot determine how much the customer has every spent, we are able to determine the total number of orders they have placed
customer = Input.cart.customer
discount = 0
message = ""
if customer
if customer.orders_count > 2 #number of orders needed to get discount
discount = 0.2 #percent discount in decimal form
message = "VIP Customer"
end
end
puts discount
@dylanjhunt
dylanjhunt / Shopify Script - X% off if customer is placing their first order
Last active April 11, 2017 16:44
X% off if customer is placing their first order
customer = Input.cart.customer
discount = 0
message = ""
if customer
if customer.orders_count == 0
discount = 0.1 #change the discount given here
message = "Thanks for placing your first order" #change the message shown here
end
puts discount
customer = Input.cart.customer
discount = 0
message = ""
if customer
if customer.orders_count > 2 #number of orders placed to get the deal
discount = 1000 #discount amount in cents
message = "VIP Customer - $10 off"
end
end
puts discount
min_discount_order_amount = Money.new(cents:100) * 30 #number of dollars needed in cart to get the discount
total = Input.cart.subtotal_price_was
discount = if total > min_discount_order_amount
0.2 #discount percentage in decimal form
else
0
end
message = "My message"
Input.cart.line_items.each do |line_item|