How to create a dynamic WhatsApp link with product name?

How to create a dynamic WhatsApp link with product name?

Danny93
Visitor
1 0 0

Hello guys!

Today I was trying to find a solution to create a dynamic text whatsapp link. I mean a whatsapp link which automatically writes something like: "Hello I'm interested in {{ product name }}".

 

Is there a way to make it work? Maybe with JS?

 

Thanks in advance!
Adriano

Reply 1 (1)

NiccosMedia
Shopify Partner
51 4 16

Yes, it is possible to create a dynamic WhatsApp link that includes information such as the product name using JavaScript. This can be done by using a JavaScript function to construct the link with the desired information and then adding it to the page as a clickable link.

Here is an example of how this could be implemented:

 

<script>
function createWhatsAppLink(productName) {
// Construct the WhatsApp link with the product name as the message
var whatsAppLink = "" + productName;
// Create a clickable link with the WhatsApp link as the href attribute
var link = document.createElement("a");
link.href = whatsAppLink;
link.innerHTML = "Click here to send a message on WhatsApp";
// Add the link to the page
document.body.appendChild(link);
}
</script>

 

To use this function, you would need to call it and pass the product name as an argument. For example:

 

<script> // Call the createWhatsAppLink function and pass the product name as an argument createWhatsAppLink("{{ product.name }}"); </script>

 

Otherwise you create a WhatsApp Business Account - There is an Option for Pre-Selected Answers/Questions when the customer clicks the link

Greetings Niclas
Senior Front-End Developer
Founder of Niccos Media
Based in Germany
niccos-media.de