Replace Shop "Add to Cart" With "View Product"
Swaps the Add to Cart buttons in shop listings for a "View product" button, so customers see the full details and options before buying.
Opens WPIDE on
Code
$wpide_view_button = 'View product'; // Button text.
add_filter( 'woocommerce_loop_add_to_cart_link', function ( $html, $product ) use ( $wpide_view_button ) {
return sprintf(
'<a href="%s" class="button wpide-view-product" aria-label="%s">%s</a>',
esc_url( $product->get_permalink() ),
esc_attr( sprintf( '%s: %s', $wpide_view_button, $product->get_name() ) ),
esc_html( $wpide_view_button )
);
}, 20, 2 );
Notes
Product pages keep their normal Add to Cart button.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.