Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
I have a form if any clients want a product in a big quantity so they can submit a form to discuss the price.
Want to get the product id so we can get identify the user's product
For that I want when user click on the button for a form so the product id will get as URL parameter and the form get and fill the product id automatically from the URL
Solved! Go to the solution
This is an accepted solution.
Hey @Mazhardev ,
I got your question correctly. So your question has two-part
1. Create a Request a quote link on the product page. To achieve it please put below code just after the buy button code in main-product.liquid, which will lead your user to the contact us form.
<div>Need a bigger quantity than available? <a href="https://gitagshop.myshopify.com?product={{ product.id}}">Request a quote!</a>
</div>
2. Read the querystring to fill contact us page, for that please refer to and the previous answer, on how to get querystring on the page.
Hope it help!
Hi @Mazhardev ,
Please use the below script to get the product id from the URL.
<script>
function getQuerystringNameValue(name) {
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec( window.location.href );
if( results == null )
return null;
else
return decodeURIComponent(results[1].replace(/\+/g, " "));
}
var _productid = getQuerystringNameValue("formid");
if(_productid != null){
// code
}
</script>
Thanks for your reply!
but I think you did not understand what I want or maybe I cant convey my question correctly
I need to pass the product id as a URL parameter for contact form
You can see the example on this page if you want
https://www.twm-bv.com/en/bikes/1004350-amigo-flip-18-inch-265-cm-boys-coaster-brake-black-blue/
Here you can see the button "Request an Offer" click on it and then check it pass the product id to form as "ean number"
Let me know if you have any question
Thanks
This is an accepted solution.
Hey @Mazhardev ,
I got your question correctly. So your question has two-part
1. Create a Request a quote link on the product page. To achieve it please put below code just after the buy button code in main-product.liquid, which will lead your user to the contact us form.
<div>Need a bigger quantity than available? <a href="https://gitagshop.myshopify.com?product={{ product.id}}">Request a quote!</a>
</div>
2. Read the querystring to fill contact us page, for that please refer to and the previous answer, on how to get querystring on the page.
Hope it help!
Hi
I found this thread and i have some questions about this:
1. I need to have the product title and the color variant into this string:
<div>Need a bigger quantity than available? <a href="https://gitagshop.myshopify.com?product={{ product.id}}">Request a quote!</a>
</div>
2: Where do i put this script?:
<script>
function getQuerystringNameValue(name) {
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec( window.location.href );
if( results == null )
return null;
else
return decodeURIComponent(results[1].replace(/\+/g, " "));
}
var _productid = getQuerystringNameValue("formid");
if(_productid != null){
// code
}
</script>
3. Do i need to change anything in the Contact form?
THanks in advance!
HK
Yes, you have to create two fields for title and color which will be passed into the URL.
Also have to amend the script to read the value from URL and assign it to form.
Starting a B2B store is a big undertaking that requires careful planning and execution. W...
By JasonH Sep 23, 2024By investing 30 minutes of your time, you can unlock the potential for increased sales,...
By Jacqui Sep 11, 2024We appreciate the diverse ways you participate in and engage with the Shopify Communi...
By JasonH Sep 9, 2024