I tried many approaches online explaining the issue, but didn't find the one could fit with my need.
I want to make a share to whatsapp
link on my website for each product, including product name, line-break and link
. Something like this:
Product Name [/r/n]
https://....
I'm using OpenCart 3. Here is php side code:
'whatsapp_text' => $result['manufacturer'] . ' - ' . $result['model'] . ' - ' . $result['name']
. $this->encodeURIComponent('\r\n' . $this->url->link('product/product', 'product_id=' . $result['product_id']))
Above code returns this:
https://api.whatsapp.com/send?text=Nurinu%20-%201310%20-%20Bra%5Cr%5Cnhttp%3A%2F%2Fwww.myweb.com%2Findex.php%3Froute%3Dproduct%2Fproduct%26amp%3Bproduct_id%3D61
According to this page (https://github.com/kriskbx/whatsapp-sharing/issues/16#issuecomment-294854157) it's possible to use window.encodeURIComponent(whatsappMessage)
to have a line-break
, but I don't know how to combine it with my php code or use it in html side:
<a href="https://api.whatsapp.com/send?text={{ product.whatsapp_text }}" data-action="share/whatsapp/share">Whatsapp</a>
UPDATE
I forgot to include the function (encodeURIComponent):
function encodeURIComponent($str) {
$revert = array('%21'=>'!', '%2A'=>'*', '%27'=>"'", '%28'=>'(', '%29'=>')');
return strtr(rawurlencode($str), $revert);
}
'\r\n'
- that’s not a line break. – Eskimoaleutrawurlencode
: Here is the output: Moonlight-263-Bra%5Cnhttp%3A%2F%2Fwww.mysite.com%2Findex.php%3Froute%3Dproduct%2Fproduct%26amp%3Bproduct_id%3D55 Any idea how to make a line break? – Moiseswhatsapp://send?text=
, which is something different than what you are using here. Not sure whether what you want is even possible using the latter; tried a few combinations of differently encoded line breaks, and they were either replaced with simple spaces, or whatsapp even redirected my in my browser to the URL with the line breaks characters completely removed from the parameter. – Eskimoaleut