Hey@KR, @Kevin Seele,
Chris Cashwell already provided a final resolution only a couple posts up from you, and you can see the updated code here: https://gist.github.com/ccashwell/38cc80a977adaf1777fc6668bd438f28
@Chris Cashwell, + others who might be able to answer
Please note that I'm an extreme novice when it comes to web development. The only code(if you can even call it that) I write is in SQL, or VBA.
Thanks for everyone's time!
In the current era, it is important for a business to have a presence on the World Wide Web. Due to such a shift in trend, every small business is coming up with a website which would help them in promotional activities. Then why there is a need in designing and development of your website?
In order to design and develop the websites, apart from using HTML and CSS codes, we also use different CMS (Content Management System) website development platforms like
• WordPress Development
• Joomla! Development
• osCommerce Development
• Magento Development
• Zen-Cart Development etc.
At www.webdesigncity.com.au before starting a project, a complete analysis is done and strategies are prepared so as to make out teamwork accordingly to deliver a flawless project. We make your website run flawlessly without any glitch as we provide a complete solution to website maintenance and support. We also guarantee success when it comes to ranking in the search engines by analyzing the keywords with respect to the project. Thus, steer your business towards fame, recognition, profitability and our team will help you to achieve the goals.
I know many of you in this thread are JS wizards, but for those who are not:
There's a pretty powerful app that does this nicely (and has a free version):
https://apps.shopify.com/discount-url
If there's an app for it, why code it yourself right?
Hey everyone, I am new to shopify and just wanted a quick solution using Shopify's existing functionality. What I wanted to do was pass a query string parameter called 'discount', and then just make a back-end call to shopify's discount link code, which will apply the discount.
So if you want to just pass a string like:
website.com/collections/?discount=DISCOUNTCODEHERE
I added the following before the </head> element in the theme.liquid file:
<!-- CUSTOM DISCOUNT APPLICATOR -->
<script>
// Gets a parameter identified by name from the url query string
function getParameterByName(name) {
var url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
var discount = getParameterByName('discount');
if (discount && discount != "") {
var xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", "https://" + window.location.hostname + "/discount/" + discount, false ); // false for synchronous request
xmlHttp.send( null );
}
</script>
Hope this helps!
Can this code also work with Cart Drawer.
I am using the code here https://finalplusshop.myshopify.com/
when some one fill the subcription pop in Header a success popup come with discount code and "Continue Reading" apply the Discount code. If I go cart and Click on Checkout Discount apply automatically. But When someone click on shop Now the Drawer open then click on "Check out" discount code is not applying.
Can you please let me know if it possible the code work with Drawer as well.
@Chris_Cashwell This is really a great solution!
I found I need to append ;path=/ to the cookie string to make the discount code work from all pages, which is the use case on our Shopify store(discount code on any URL in our store should work).
So, only one line change in the theme.liquid snippet for our use case. The snippet for cart.liquid remains the same.
<script> /* Put this in theme.liquid, preferably right before "</body>" */ (function() { var discountParam = document.location.search.match(/discount=(\w+)/); if (discountParam && discountParam.length > 1) { document.cookie = discountParam[0] + ";path=/"; } })(); </script>
Subject | Author | Latest Post |
---|---|---|
Subject | Author | Posted |
---|---|---|
34m ago | ||
2 hours ago | ||
2 hours ago | ||
3 hours ago | ||
4 hours ago |
User | Count |
---|---|
326 | |
77 | |
72 | |
65 | |
56 |