Hi,
Is it possible to create a site-wide discount or a colletion-wide discount without a code ?
I know I can do it per product, but for site-wide discount that would mean to edit every single variant on my store (over 200K) and with the API it will take about 15 hours everytime I want to create a sale on the site...
Thanks.
Hi isaacdvory,
I am so happy to support you about my app. Disocunt Master - You can create a site-wide discount or a collection-wide discount WITHOUT a code. You can create discount for all products, specific products or collections in a few minutes.
After the discount time, the coverted price will become the origial price. Every process will be worked automatically. Besides, this app has more features such as countdown timer and stock countdown. You can try them!
You can use the Launchpad app to do this for free. its Shopify plus only, but works really well.
I'm a little late to the party but instead of using an app to change the actual price of your items you could just use the Script Editor app and create a script that changes the price at the checkout.
Something like
Input.cart.line_items.each do |line_item|
#skip gift cards
next if line_item.variant.product.gift_card?
#apply a 30% discount to line item
line_item.change_line_price(
line_item.line_price * 0.7,
message: 'Happy holidays, have 30% off',
)
end
Output.cart = Input.cart
That will save you on time and it's very easy to combine funcitonality in a single script if you have other discounts at play or if different discounts apply to differnet items.
Cheers,
Elliott
The only issue with that is it does not show on the front end. So it would work in checkout but customers would see it at full price on checkout. The launchpad app shows it on front end and checkout. I wish scripts did too if you wanted them to.
Dont use an app if you don’t have to. Launchpad does this better than an app will. Don’t waste your money.
Hi there @Mandelbrotian! I've read through a few of your replies on here. First, thank you for taking the time to do what you do, I'm sure I speak for all of us when I say we really appreciate it.
I am new to Scripts and Ruby and have only been at this for about a day or so. In my multiple searches online I have stumbled across your posts may times so I figured I'd just ask..
I am trying to setup a price rule using scripts that takes into consideration two things: 1. The product_type and 2. The total quantity of all matching product types in the cart. For example: if you have 10 individual line items in your cart but all of them are product_type 'cameras' then you get a 15% discount because you're buying 10 'cameras'. I found this bit of code in the Shopify examples and it looked quite promising when I came across it.
# Define a list of price tiers. PRICE_TIERS = [ # Pricing tiers for Shoes { product_types: ['Shoes'], group_by: :product, # :product or :variant tiers: [ { quantity: 10, discount_percentage: 10, discount_message: '10% off for 10+' }, { quantity: 50, discount_percentage: 15, discount_message: '15% off for 50+' } ] } ] # You shouldn't need to edit anything below this line, unless you're a developer # and know what you're doing :). ## # Tiered pricing campaign. class TieredPricingCampaign def initialize(partitioner, tiers) @partitioner = partitioner @tiers = tiers.sort_by { |tier| tier[:quantity] } end def run(cart) @partitioner.partition(cart).each do |k, items| total_quantity = items.map(&:quantity).reduce(0, :+) applicable_tier = find_tier_for_quantity(total_quantity) unless applicable_tier.nil? apply_tier_discount(items, applicable_tier) end end end private def find_tier_for_quantity(quantity) @tiers.select { |tier| tier[:quantity] <= quantity }.last end def apply_tier_discount(items, tier) discount = get_tier_discount(tier) items.each do |item| discount.apply(item) end end def get_tier_discount(tier) PercentageDiscount.new(tier[:discount_percentage], tier[:discount_message]) end end ## # Select line items by product type. class ProductTypeSelector def initialize(product_types) @product_types = Array(product_types).map(&:upcase) end def match?(line_item) @product_types.include?(line_item.variant.product.product_type.upcase) end def group_key @product_types.join(',') end end ## # Apply a percentage discount to a line item. class PercentageDiscount def initialize(percent, message = '') @percent = Decimal.new(percent) / 100.0 @message = message end def apply(item) line_discount = item.original_line_price * @percent new_line_price = item.original_line_price - line_discount if new_line_price < item.line_price item.change_line_price(new_line_price, message: @message) end end end ## # A pricing tier partition. class TierPartitioner def initialize(selector, group_by) @selector = selector @group_by = group_by end def partition(cart) # Filter items items = cart.line_items.select { |item| @selector.match?(item) } # Group items using the appropriate key. cart.line_items.group_by { |item| group_key(item) } end private def group_key(line_item) case @group_by when :product line_item.variant.product.id when :variant line_item.variant.id else @selector.group_key end end end ## # Instantiate and run Price Tiers. PRICE_TIERS.each do |pt| TieredPricingCampaign.new( TierPartitioner.new( ProductTypeSelector.new(pt[:product_types]), pt[:group_by] ), pt[:tiers] ).run(Input.cart) end ## # Export changes. Output.cart = Input.cart
The above code can be found on Shopify's Example Scripts.
Unfortunately, although this particular example works for volume discounts, it completely ignores the product_type defined in the first few lines. I know this because no matter what product I choose in the scripts editor, as long as the quantity meets the defined line quantity defined discounts, the discount gets applied.. (and we don't sell shoes) =)
I've also tried to go back to basics by using the vanila line item code in scripts which I have modified to look like this:
DISCOUNTS_BY_QUANTITY = { 10 => 15, } Input.cart.line_items.each do |line_item| next if line_item.variant.product.gift_card? if line_item.variant.product.product_type.include? "Cameras" quantity, discount = DISCOUNTS_BY_QUANTITY.find do |quantity, _| line_item.quantity >= quantity end end next unless discount message = "#{discount}% off when buying at least #{quantity}." line_item.change_line_price( line_item.line_price * (Decimal.new(1) - discount.to_d / 100), message: message, ) end Output.cart = Input.cart
The above code works to isolate any product_types that contain the word Camera but is only applied to individual line items not the sum of all line items that are also cameras.
Anyhow, I'm not really looking to reinvent the wheel here. I went into this thinking I'd probably find some "close-enough" bit of code that would do this easily. Any pointers you could offer would go a very long way to helping us complete this script!
Hi @UncleCharles! I restored your post.
Our spam engine is still learning so if you notice this occurring again submit a report so we can restore it for you
TyW | Online Community Manager @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit the Shopify Help Center or the Shopify Blog
Hi @UncleCharles, thanks for the accolades!
I've made a few assumptions here,
1. You're only applying the discount for a single product type
2. You're only allowing for a single level of discount
3. These run in tandem with cart discount codes
Given those, the following script should do the job
DISCOUNT_TYPE = "Sweaters" DISCOUNT_PRODUCT_MIN = 10 DISCOUNT_PERCENT = 15 DISCOUNT_MESSAGE = "#{DISCOUNT_PERCENT}% off when buying at least #{DISCOUNT_PRODUCT_MIN} #{DISCOUNT_TYPE}." discount_applicable_products = 0 Input.cart.line_items.each do |line_item| next if line_item.variant.product.gift_card? if line_item.variant.product.product_type.include? DISCOUNT_TYPE discount_applicable_products += line_item.quantity end end if discount_applicable_products >= DISCOUNT_PRODUCT_MIN Input.cart.line_items.each do |line_item| if line_item.variant.product.product_type.include? DISCOUNT_TYPE line_item.change_line_price( line_item.line_price * (Decimal.new(1) - DISCOUNT_PERCENT.to_d / 100), message: DISCOUNT_MESSAGE, ) end end end Output.cart = Input.cart
It's essentially the same as the second script you posted, but it assesses how many of the critical type are in the cart before applying the discount to all products that have that type.
Hope that helps! If you need any scripts written in the future feel free to contact me directly.
Cheers,
Elliott
User | Count |
---|---|
1 | |
1 | |
1 | |
1 | |
1 |