Sending Selected Variant SKU via Whatsapp Button

I am trying to send the selected variant SKU via my custom built whatsapp button but it’s sending only pre-selected SKU via whatsapp. I want your help to suggest me a proper code snippet to solve this problem.

file name product-template.liquid

The code for variable sku i am using.

{% assign current_variant = product.selected_or_first_available_variant %}
SKU-{{ current_variant.sku }}

The whatsapp button code.

[Buy on Whatsapp](https://wa.me/91XXXXXXXXXX?text={{ current_variant.sku }})

The Problem with this code.

When i open a product page and click on buy on whatsapp button it sends pre-selected SKU but when i select any other variant it send that previews pre-selected SKU not the current one i have selected. The current_variant.sku data doesn’t change accordingly but shows on product page below product.title correctly.

Also i want some condition on my whatsapp button.

  1. if the product.type is = “X” then whatsapp button should be visble otherwise not.
  2. if the current selected variable is not available in inventory the whatsapp button should be hide just like Shopify’s built-in regular add to cart or buy now button does.

* All these conditions should be in real time i.e. doesn’t requires the page reload/refresh.

I am using Debut Theme.

Thanks
I would greatly appreciate your help.

Hi @panwar ,

It will need modification in default JS which is responsible for changing the button status and price of product when we change the product variant.

and with the help of liquid code it is possible to add or remove the Whatsapp buy button on product page on the basis of product tag,

Thanks

How to achieve this?

@Anonymous

@panwar

if you are asking about the code then I could not provide you because this will need lots of code modification in JS and time taking task and it is not possible to write a code from outside by watching the store frontend and give you to just paste for the functionality the you had mentioned

Thanks