I have tried the coding offered in the other related questions but they are not working - possibly because I'm not good at this. I want to add a button to only one product alongside the 'add to cart' button that will link to an external website. This must appear on the shop page and the product description page because I don't want international buyers to 'add to cart' without knowing they have an international option that saves on delivery. Just a heads up - I am not a developer but can navigate in code with direction... please help this lost soul
Below code help you to add the external link button. copy the code and add to your theme function.php file. its work only with product id 41 and 53 in my example you can replace with your product id in which you wants to show this button.
add_action('woocommerce_after_add_to_cart_button', 'additional_single_product_button', 20); // add button in single product page
add_action('woocommerce_after_shop_loop_item', 'additional_single_product_button', 20); // add button in shop page
function additional_single_product_button()
{
global $product;
// Define your targeted product IDs in the array below
$targeted_product_ids = array(41, 53);
if (in_array($product->get_id(), $targeted_product_ids)) {
echo '<br><a href="https://google.com" class="button">i am external button</a>'; // your button
}
}
i wish it help you to fix the problem.
Thanks.