Personalized checkout and custom promotions with Shopify Scripts
Hey Everyone!
Currently running the Tiered Pricing Script found here:
Things that arent working:
Custom development:
After getting the above working I need to build a table on the front end of the site, below the add to cart buttons, to show this discount opportunity to the customer. I've attached below an example of one that I think would work well. It would show:
Quanitity Examples - Discount % - Resulting Line Item Price
Thanks in advance team!
I haven't had issues with it discriminating appropriately between line items within a cart. Best guess is that your product selectors are casting a wider net than you intend, but hard to know without seeing what your inputs are for the PRODUCT_DISCOUNT_TIERS section.
As for the table showing the customer the discounts, I put together a really crude table for ours like this:
<table>
<tbody>
<tr>
<th></th>
<th style="color: white; font-weight: bold;">Standard</th>
<th style="color: white; font-weight: bold;">X Large</th>
</tr>
<tr>
<td style="font-weight: bold;">2 - 4</td>
<td>$30</td>
<td>$35</td>
</tr>
<tr style="background-color: #f1f1f1;">
<td style="font-weight: bold;">5 - 24</td>
<td>$28</td>
<td>$33</td>
</tr>
<tr>
<td style="font-weight: bold;">25 - 34</td>
<td>$23</td>
<td>$28</td>
</tr>
<tr style="background-color: #f1f1f1;">
<td style="font-weight: bold;">35+</td>
<td>$20</td>
<td>$25</td>
</tr>
</tbody>
</table>
Which ends up looking like this on the front end:
Thanks for your reply! We moved to an alternative script I found online, unfortunately now this one is TOO restrictive, where it is requiring a customer to select multiples of the EXACT size/flavour. Ideally, we want them to be rewarded with a discount on the same item in ANY flavour where they purchase two or more of. I have included the script below, surely there would be a balance we could run between the two scripts. It's very strange that the original Shopify script provided wasn't working as intended.
Again, here is the script below we are CURRENTLY running - I have implemented a similar HTML table also, thanks for your feedback on this:
DISCOUNTS_BY_QUANTITY = {
3 => 10,
2 => 5,
}
Input.cart.line_items.each do |line_item|
next if line_item.variant.product.gift_card?
quantity, discount = DISCOUNTS_BY_QUANTITY.find do |quantity, _|
line_item.quantity >= quantity
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
Ah, I see, that honestly seems a little tough. Since each variant is is its own line item, you need concatenate all the variants for a given product into a single array before running the discount math on it. That's a bit beyond my level of script editing, but if you know someone good with Ruby, that's what I'd request. Otherwise, honestly, it might be worth the cost to pay for one of those quantity discount apps.
I had the same complex pricing issues, but installed a volume pricing app and the job was done.
Tried several apps, and would highly recommend these folks;
Tried all available apps (including the one you mentioned) but found them very slow and buggy. It didn't like our discount code field in our cart (before checkout) and was erroring.
Scripts are the way to go and HTML table (which is working) - ill keep working through the script issues and report back.
Open to other suggestions also
Hey m8,
There is a option page in the app which allowes you to turn those discount code fields off, or design/customize it (colors, fonts, etc).
Nah man that app sucks. I have had plenty of custom apps built previously and it is laggy, glitchy, and the ui/ux is average at best.
Well.. thats a subjective matter I suppose 😃.
There is nothing subjective about an app that does not do what it states. or negatively impacts site performance.
I am here for assistance with a script. Please stay on topic.
Hey Community! As the holiday season unfolds, we want to extend heartfelt thanks to a...
By JasonH Dec 6, 2024Dropshipping, a high-growth, $226 billion-dollar industry, remains a highly dynamic bus...
By JasonH Nov 27, 2024Hey Community! It’s time to share some appreciation and celebrate what we have accomplis...
By JasonH Nov 14, 2024