php ACTION not working – replacing “Add to Cart” buttons with “View Product”
-
I would like to replace the “Add to cart” button with a “View Product” button almost everywhere. This is because I expect that my customers will want to read about the product before adding it to the cart.
The “Add to Cart” button appears below products in many different cases, such as when using the Products by Category block, Hand Picked Products block, and Related products block (by default included on the single post page). After many hours of searching, I am unable to find a solution, or even a partial solution. Or, to be precise, the solution I found doesn’t appear to be working, which is why I can’t continue researching and came here. The code is:
#this line is supposed to remove the default button entirely remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 ); #and this line is supposed to add some custom html - a button with the correct link, of course add_action( 'woocommerce_after_shop_loop_item', 'wptechnic_custom_view_product_button', 10); function wptechnic_custom_view_product_button() { global $product; $link = $product->get_permalink(); echo '<a href="' . $link . '" class="button wptechnic-custom-view-product-button">View Product</a>'; }
Can anyone point me in the right direction why this does not work? Other functions and filters in my function.php file work correctly.
I am using wordpress 6.4.1 and my woocommerce version is 8.2.2
Thanks for the help!
- The topic ‘php ACTION not working – replacing “Add to Cart” buttons with “View Product”’ is closed to new replies.