I have the following echo <<EOF
onclick event and want to convert it to simple echo, How can I do it:
echo <<<EOF
<button type="button"
onclick="location.href=((document.getElementById('{$product->get_id()}')!=null) ? document.getElementById('{$product->get_id()}').value : '{$product->add_to_cart_url()}');" >
Add To Cart </button>
EOF;
I tried concatenating but it didn't work.
How can I echo the onclick event with simple echo
instead of echo <<<EOF...EOF;
?
Heredoc is useful when you have a string containing both '
and "
.
Having said that, here you go, just escape with backslashes:
echo "<button type=\"button\" onclick=\"location.href=((document.getElementById('" . $product->get_id() . "')!=null) ? document.getElementById('" . $product->get_id() . "').value : '" . $product->add_to_cart_url() . "');\" >
Add To Cart </button>";