Updating the Wholesale Discount Script
-
Login to Shopify Admin
-
Click on APPS
-
Click on the Shopify Script App
-
On the main screen you will see two items -
- Wholesale - TGTG Discount Script
Allows discount stacking - Wholesale - TGTG Discount Script - No Stack (PUBLISHED)
Does not allow stacking
- Wholesale - TGTG Discount Script
-
You CANNOT edit live/published scripts, but you can duplicate them to work on them.
-
Click on Wholesale - TGTG Discount Script - No Stack
-
On the top of the page, click the DUPLICATE button
-
Once duplicated, you can change the title to something more descriptive
-
Interface below:
Left Side = Source code of the script
Center = Cart where you can test different options to determine if the updates work as intended
Right = The output screen, click on RUN SCRIPT to see the generated output from your cart.Note, if you don’t see all three screens, click on the CODE / INPUT / BOTH buttons to toggle around.
-5cb213faaed2a3464eb6a29fdd22fc0b.png)
- Editing the code blocks
Set the variable TAGPRICING = the customer tag you want this script to target.
TAGPRICING = 'Wholesale - TGTG'
Leave CUST_DISCOUNT alone
CUST_DISCOUNT = false
Customer Check Block
This block checks to see if the customer on the checkout is tagged with TAGPRICINGs variable. If so, we set the CUST_DISCOUNT = true
if !Input.cart.customer.nil?
Input.cart.customer.tags.each do |tag|
if tag == TAGPRICING
CUST_DISCOUNT = true
end
end
end
Discount Code Reject Script Discount
I wrote this out fully so it is simpler to read. The first if checks if the user already is able to get the discount, if so - the next if checks if the discount code parameter exists on the checkout. If there is a discount code (the else block) we set the CUST_DISCOUNT variable to false, as they no longer can qualify for the script discount.
if CUST_DISCOUNT
if Input.cart.discount_code.nil?
else
CUST_DISCOUNT = false
end
end
Actual Discounting (wrapping added for easier reading below)
If the user has qualified for the discount, we loop through each line item and change the price. Multiplying by 0.95 will give you a 5% discount on each line item. MESSAGE = the message displayed to the customer.
if CUST_DISCOUNT
Input.cart.line_items.each do |line_item|
line_item.change_line_price((line_item.line_price * 0.95),
message: "5% Discount")
end
end\
Some further info on shopify scripts:
Online Script Builder - This is very much a use at your own risk as it typically outputs really complex code for simple items that is hard to read and should always be thoroughly checked