Click to whatsapp chat!

Hi weweb fam! I am trying to create a button that links to whatsapp no. with prefilled message.

I want to send my cart as prefilled message but cannot figure out how to put the array into structured text.

For example I want to display such message:

"Hi shop!

I want to buy
5 apples
2 oranges
3 banana

My total is $24
Please confirm my order"

I can’t figure out also how to make spaces at the whatsapp link. Please help, thank you guys.

Same situation when displaying items in a table, I can’t figure out how to make format the values

Have a look to the formulas for text manipulation to concatenate strings.

In your case maybe a bit of javascript can be easier. You can use template literals:

`Hello I want ${cart[0].amount} ${cart[0].product}. Thanks.`
2 Likes

Thank you dorilama, appreciate it. I will try applying that

Let me know how it goes :slight_smile:

Sorry I read the docs but don’t quite understand. How does it work with arrays that I don’t know how many index there is?

let text = 'your cart has'
for (let product of cart){
  text += ` ${product.amount} ${product.name}`
}
1 Like

If you prefer a nocode way you can add a workflow that calculate the text iterating over the array with a for loop.
Have a look at the options you have with the new workflow branching.

1 Like

thanks I will try and do this

Hi dorilama, I think I got the concatenate part, and how to bind the whatsapp number to a value, however I still have trouble with the for loop, I don’t know how to do it, I prefer to do it in no-code since I understands better that way.

Is it correct that I should make a new variable containing for loop of the product quantity+product name? And how do I do it?

I’m on my phone now but you should be able to make it following the for loop docs.
You need to create a text variable to store the result. It works as any other variable in weweb: you need to create it in advance (not inside the workflow).

sorry I’ve tried to understand the docs but couldn’t, right now, I created a workflow containing for loop reiterating over my cart products and quantity, and it returns my products and quantity one by one(each loop), how do I put them in a list in my link?, also the concatenate, how can I make the words skip a line? I seem to only able to put one space between the words. thank you

inside the loop you need to add a “change variable” action where you concatenate the strings.
You can add a new line in a string with \n. You need to check whatsapp docs to see if they allow new lines or if they use a special way for adding them

1 Like

Thank you, I figured how to add new lines, but to concatenate the loop still can’t figure it out. So I set the loop for my cart array, how do I concatenate all the products and quantity inside?

I am still from mobile.

Have you tried to set up the loop in the workflow?
Have you added the change variable action inside the loop?
Have you seen what workflow variables are available to use in the loop workflow? You should have access to the current loop item.
How is your workflow looking?

Read again the documentation, maybe try to implement the example first so you grasp how to use it and then adapt it to your specific case.

I set up the loop, tried the change variable, yes I can access the current loop item, but I don’t know how to add to the next loop item and so on. All I was able to do was change the variable to the current loop item each loop, I cannot figure out how to add

if your string variable to store the result it’s called “final-string” then on each loop you need to change “final-string” with the value of “final-string” + the string that you want to add.

1 Like

Thank you so much, finally got it. I created 2 variables, one inside the loop, another outside for the final string. Thank you dorilama :pray: :pray:

Way to go! :slight_smile: