Replace add to cart button with the product page link & Change add to cart text

`Replace add to cart button with product single linked to product page on shop pages in WooCommerce 3

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! 😊

Previous Code

WooCommerce Discount based on Cart Item

A discount on the total order with condition based ...

0 Comment

    Leave a Reply

    Your email address will not be published.

    13 + two =

    Get WooCommerce product info

    Show product info in the place as you wish to. It ...

    WooCommerce Discount based on Cart Item

    A discount on the total order with condition based ...

    Remove WooCommerce checkout fields

    Remove WooCommerce Checkout field with simple filt ...

    WooCommerce Checkout Conflict with Bootstrap 4.x

    WooCommerce Checkout Conflict with Bootstrap 4.x. ...

    Update WooCommerce Delivery cost with condition

    Change Delivery price base on what item in cart ...

    ACF

    JavaScript

    jQuery

    Others

    PHP

    WooCommerce

    WordPress

    skype

    Need Coding Help?

    Connect Skype
    top