I have this code that I have added to WP site using the Snippets plugin. The code is intended to display a “View Product” link in addition to the “Add to Cart” button for WooCommerce.
The code works! It shows the “View Product” link as needed.
THE ISSUE:
The issue however is that the “View Product” link only appears on the Shop page (which displays all items on the store) and on the item Categories/Tags pages.
The “View Product” link doesn’t appear for Related Products, Cross Sells, or Handpicked Products, etc.
I need the “View Product” link to appear for all items wherever they are displayed on the website.
I could really use some help with this. Thanks in advance!
This is the code that I have implemented:
/**
* @snippet Add ‘View Product’ button before ‘Add to Cart’ in WooCommerce
* @compatible WC 6.3.1
*/
add_action('woocommerce_after_shop_loop_item', 'wptechnic_custom_button_view_product', 5 );
function wptechnic_custom_button_view_product() {
global $product;
/* Ignore for Variable and Group products
if( $product->is_type('variable') || $product->is_type('grouped') ) return;
*/
// Display the custom button
echo '<a style="margin-right:5px" class="button wptechnic-custom-button-view-product" href="' . esc_attr( $product->get_permalink() ) . '">' . __('View product') . '</a>';
}