December 28, 2024
1 min read

WooCommerce ‘add to cart’ button work with ajax so the end user cant see product details on your site. if you want to change your button ajax functionality with a link to a product single page then you can easily do with a filter hook.

Put this code on the functions.php file of your theme (child theme recomanded)

functions.php
//eplace add to cart button with a product page link
add_filter( 'woocommerce_loop_add_to_cart_link', 'mukto_cart_btn', 10, 2 );
function mukto_cart_btn( $button, $product  ) {
    $button_text = __("View Product", "woocommerce");
    $button = '<a class="button" href="' . $product->get_permalink() . '">' . $button_text . '</a>';

    return $button;
}

Now if you just want to change only the text of the ‘add to cart’ button text then use this code.

functions.php
//chnage button text 
add_filter('woocommerce_product_add_to_cart_text', 'mukto_btn_text');   // 2.1 +

function mukto_btn_text()
{
    return __('Add to bag', 'woocommerce');
}

Thank you! 😊

Leave a Reply

Your email address will not be published. Required fields are marked *

JQuery Auto Hight

jQuery height change after a specific time interval

Jquery Replace specific text in all element

Scenario Imagine you have a set of elements with the class specific_class, and they all contain the phrase “old text.” You want to replace this phrase with “New text” programmatically. The Solution Here’s a simple jQuery script to achieve this: How It Works Things to Keep in Mind Extending the Script jQuery provides a quick […]

ACF

Advanced Custom Fields code snippet

Advance custom field Link Field, Flexible content Field, Gallery and tricks code snippet

How to Add Page Template from Your Plugin

Add custom page template from your plugin with simple code snippet.

Web Development Project in mind?

if you looking for a web developer for paid contribution to your project I am available for work.

Mukto
Mukto

Click the button below to chat with me.