I have only 2 products. I want to provide custom link to each respective product on product listing page.
I am using below code...
add_action('woocommerce_after_shop_loop_item', 'add_a_custom_button', 5 );
function add_a_custom_button() {
global $product;
if (is_product() == 3557 || is_shop() || is_product_category() || is_product_tag()):
?>
<div style="margin-bottom:10px;">
<a class="button custom-button" href="https://example.com/redirect/3557/">Buy @ Store1</a>
</div>
<?php
endif;
if (is_product() == 3541 || is_shop() || is_product_category() || is_product_tag()):
?>
<div style="margin-bottom:10px;">
<a class="button custom-button" href="https://example.com/redirect/3541/">Buy @ Store2</a>
</div>
<?php
endif;
The issue with above code is that it shows both html buttons for each product.