in functions.php of my templatefolder, I add this code to be able to have a second link on the product page.
but the result is an error 500.
I guess the product id part is wrong. Does anybody see how to solve this?
Woocommerce Version 3.4.5
function my_extra_button_on_product_page() {
global $product;
echo '<a class="single_add_to_cart_button button alt" href="?add-to-cart'<?=$product->get_id() ?>'">Second Link</a>';
}
I expect that the link that gets generated, has the add-to-cart=[‘product_id’] of course with the correct Product_id
But I get error 500
3
Answers
You have an error in your PHP code. When you insert PHP code in a string in a PHP file (not a template) you do not have to use the PHP tags.
Here is it:
NOTE
This will produce this link
is this what you want? Don’t you need a different link?
Looks like there is a syntax error in your echo statement please try this :
Add this code in your
functions.php
to display another button besideAdd to cart
button