I have 2 categories on my WooCommerce website. Let’s say:
- "cat1"
- "cat2"
I have implemented the following code to modify the "Add To Cart" text to "View Product" for all the products.
add_filter( 'woocommerce_loop_add_to_cart_link', 'replace_loop_add_to_cart_button', 10, 2 );
function replace_loop_add_to_cart_button( $button, $product ) {
$button_text = __( "View Product", "woocommerce" );
return '<a class="button" href="' . $product->get_permalink() . '">' . $button_text . '</a>';
}
But what I don’t know is how to modify the button text to "View Cat 1" for category 1 products, and "View Cat 2" for category 2 products.
2
Answers
Found out the solution:
Hope it helps those in a similar situation :)
Hope you are doing well i add pretty simple solution for you below is your magic.
your second question answer is