Changing Woocommerce "Add to cart" button to "view product" button Changing Woocommerce "Add to cart" button to "view product" button wordpress wordpress

Changing Woocommerce "Add to cart" button to "view product" button


Try this alternative that will replace add to cart button by a linked button to the product in Shop and archives pages

// Replace add to cart button by a linked button to the product in Shop and archives pagesadd_filter( 'woocommerce_loop_add_to_cart_link', 'replace_loop_add_to_cart_button', 10, 2 );function replace_loop_add_to_cart_button( $button, $product  ) {    // Not needed for variable products    if( $product->is_type( 'variable' ) ) return $button;    // Button text here    $button_text = __( "View product", "woocommerce" );    return '<a class="button" href="' . $product->get_permalink() . '">' . $button_text . '</a>';}

Code goes in function.php file of your active child theme (or theme). Tested and works.


Use this code to replace the default “Add to Cart” button with “Read More” (or anything you like) linking to the single product page.

// First, remove Add to Cart Buttonremove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );// Second, add View Product Buttonadd_action( 'woocommerce_after_shop_loop_item', 'shop_view_product_button', 10);function shop_view_product_button() {global $product;$link = $product->get_permalink();echo '<a href="' . $link . '" class="button addtocartbutton">View Product</a>';}

You can add this PHP Snippet at the very bottom of your active child theme (or main theme) functions.php file. Code Source