AgentReadyAI visibility appCaffeine & CommerceShopify agency
Caffeine and Commerce
Caffeine and Commerce
By Dylan HuntAugust 9th, 2024shopifyscripts

Black Friday Cyber Monday Shopify Scripts for Free Gifts

Shopify Scripts is being retired on June 30, 2026.

The Ruby Scripts and Script Editor used in this tutorial stop running after that date. The replacement is Shopify Functions (also called checkout functions), which is faster, available beyond Shopify Plus, and built for the new checkout. If you run Scripts today, plan your migration now.

Black Friday Cyber Monday Shopify Scripts for Free Gifts

Hey guys,

This script will allow you to offer a free gift if the price is over a certain price. I set it up here to allow for 4 items to be chosen to be a free gift. This will come along with a bit of work to setup the frontend, but bundling to offer a free gift has been really popular on Shopify lately and I wanted to start the dialog here.

min_discount_order_amount = Money.new(cents:100) * 75

discount_products = [xxxxxxxxxx, xxxxxxxxxx, xxxxxxxxxx, xxxxxxxxxx]

total = Input.cart.subtotal_price_was

discount = if total > min_discount_order_amount
  1
else
  0
end

message = "You've earned a free gift"
did_discount = false

if Input.cart.discount_code == nil && !Input.cart.subtotal_price_changed?
  Input.cart.line_items.each do |line_item|
    product = line_item.variant.product
    next if product.gift_card?
    next unless discount_products.include?(product.id)

    if discount == 1 && !did_discount
      new_price = Input.cart.subtotal_price_was - line_item.variant.price
      unless new_price < min_discount_order_amount
        if line_item.quantity > 1
          new_line_item = line_item.split(take: 1)
          new_line_item.change_line_price(Money.new(cents: 0), message: message)
          did_discount = true
          Input.cart.line_items << new_line_item
        else
          line_item.change_line_price(line_item.line_price * (1-discount), message: message)
          did_discount = true
        end
      end
    end
    break
  end
end

Output.cart = Input.cart

This will ensure that if your cart is over $75 and one of the 4 product id's marked with x's is in the cart it will be free.

Make your store agent-ready

Get found and recommended by AI shopping assistants.

AgentReady adds Schema.org structured data, an llms.txt directory, and an AI-readability audit to your Shopify store, so ChatGPT, Perplexity, and Google can understand and recommend your products. Free for stores under 500 products.

Comments

Every comment here comes from a verified email. Write yours, confirm from your inbox, and it's live.

Loading comments…

Leave a comment

ShareXLinkedInFacebook

Written by Dylan Hunt, Founder, Caffeine and Commerce. We build Shopify stores that rank and that AI agents can read. Have a project? Get in touch.