I want to change the cart button text on archive pages to an icon.
I found a snippet which does that. But that also changes the link of the cart button:
add_filter( 'woocommerce_loop_add_to_cart_link', 'ts_replace_add_to_cart_button', 10, 2 );
function ts_replace_add_to_cart_button( $button, $product ) {
if (is_product_category() || is_shop()) {
$button_text = __("View Product", "woocommerce");
$button_link = $product->get_permalink();
$button = '<a href="' . $button_link . '">' . $button_text . '</a>';
return $button;
}
}
Is there a way to change only the text of the button?
I know, that I could change the template file /loop/add-to-cart.php
. But I need a solution based on a function.
My Answer:
Add to cart', 'woocommerce' );
$button = str_replace( $button_text, '', $button );
}
return $button;
}
This code snippet will replace the text "Add to cart" with a shopping cart icon on archive pages. Just add this code to your theme's functions.php file.
Rate this post
4 of 5 based on 8236 votesComments