Is there any way of changing WooCommerce Add to Cart button into “View Product” or “Add to Basket” or anything you like?

WooCommerce, the eCommerce platform for WordPress, shows “Add to cart” button by default on your shop page and archive pages.

What if you want to show “View Product” button instead of “Add to Cart” for your customers?

Well, there is.

How to Change WooCommerce Add To Cart button text with ‘View Product’

Instead of showing the default WooCommerce Add To Cart button, you can remove or replace that with a “View Product” button (or anything you like) linking to the single product page.

WooCommerce Add to Cart

Here’s the simple snippet code.

PHP Snippet: Change WooCommerce ‘Add to Cart’ button text into ‘View Product’

// First, remove Add to Cart Button

remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
// Second, add View Product Button
add_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>';

Now, if you want to display anything else instead of “View Product“, you can replace the view product text from the highlighted line (11) with your own.

WooCommerce View Product Button

If the above code does not work for your website, you may try adding this one instead:

// Replace WooCommerce 'Add To Cart' button with 'View Product'
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  ) {
    // 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>';

How to add PHP Snippet code to your WordPress site?

There are many ways of adding a PHP Snippet code to your WordPress website. You can add this PHP Snippet at the very bottom of your active child theme (or main theme) functions.php file. You can also add this code using any third-party plugin like ‘Insert Headers and Footers‘ or ‘Code Snippets‘ plugin.

WooCommerce Add to Cart replaced with View Product Button

Does this Code work for any theme?

This PHP Snippet code uses default WooCommerce Loop. Therefore, if your theme using the default WC loop to display ‘Add to Cart’ button, then it surely will work.

However, if your theme has custom pages using custom page builder plugins that use different functions to show ‘add to cart’ button, then it may not work for your website. In that case, hire a Pro developer or contact your theme provider.

Did this code work for your website? Or you’re having difficulties? Either way, let me know by leaving a comment below right now.

Avatar for Muhammad Tamzid

Muhammad Tamzid, the founder of WPTechnic, is a WordPress Enthusiast with a passion to help beginners learning WordPress. Also managing WPrevival, a 24/7 WordPress Website Development, Maintenance & Security Service company.


  1. Avatar for Miguel Parraud Cordeyro
    Miguel Parraud Cordeyro Reply

    Muhammad, I need to do exactly this but on the home page inside the following shortcode

    [products limit=”3″ columns=”3″ visibility=”featured” ]

    Is there a way to implement this that only affect the products on the shortcode?

    thank you!!!

    • Avatar for Muhammad Tamzid

      Hi Miguel,
      You cannot do anything like that, I’m afraid. Are you using any page builder? how are you using this shortcode? Give me something more. If I come up with a solution, I will let you know.

Write A Comment