Image default

Change Link “Add to Cart” for a Link to the Product in WooCommerce

WooCommerce is an excellent tool for those of us who use WordPress CMS, but unfortunately, it has little flexibility when it comes to configuring it.

One of the most frequent queries is about it’s famous ” Add to cart ” button, a button that appears by default in the list of products and in the extended ones.

From time to time, a customer has the need to change the operation of the button ” Add to cart ” and convert it, simply, a button to access the extended or single page.

While in almost all WooCommerce templates this function is made by a link assigned to the product image, we must admit that it can be a bit confusing for the uninitiated.

To make this change of functionality and to be shown in the loop or list of products, just go to our file functions.php

And we insert the following code:

// First, we deactivate the "Add to cart" button
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
// Then we create our own button
add_action( 'woocommerce_after_shop_loop_item', 'ver_product_looping', 10);
function ver_product_looping() {
global $product;
$link = $product->get_permalink();
echo 'a href="' . $link . '" class="button addtocartbutton"> Ver product ';

Related posts

How to Add Variable Products in WooCommerce


How to Customize Add to Cart Button in WooCommerce


How to Customize WooCommerce Product Variations