Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove "View Cart" link which appears after click on the "Add To Cart" button in WooCommerce

I am using Wordpress version 4.5.2 and WooCommerce version 2.5.5.

After clicking on the "Add To Cart" button, one link appears "View Cart".

Can anyone help me to remove that link?

Text to remove:

Text to remove

like image 303
Sunita Avatar asked Dec 08 '25 00:12

Sunita


2 Answers

Because this functionality is hard-baked into the JS of WooCommerce, you can't disable it with a filter or hook. However, after trawling through WC's code, I discovered a handy (and slightly hacky) caveat:

If you add the following empty div to the same container as your Add to Cart button, the View Cart (or View Basket if you're in the UK) link won't get added:

<div class="added_to_cart"></div>

This is because the Javascript file checks to see if an element with that class already exists:

// View cart text
if ( ! wc_add_to_cart_params.is_cart && $thisbutton.parent().find( '.added_to_cart' ).size() === 0 ) {
    $thisbutton.after( ' <a href="' + wc_add_to_cart_params.cart_url + '" class="added_to_cart wc-forward" title="' +
        wc_add_to_cart_params.i18n_view_cart + '">' + wc_add_to_cart_params.i18n_view_cart + '</a>' );
}

If it finds an existing .added_to_cart element, it won't try to append another.

It's worth noting that Sathyanarayanan G's answer should totally work too (and I'm surprised it didn't - that sort of points to something else being wrong), but in a slightly different way.

like image 71
indextwo Avatar answered Dec 10 '25 14:12

indextwo


Adding the below line of code to your child theme's style.css should do the trick.

a.added_to_cart {display:none !important}
like image 43
Craig Avatar answered Dec 10 '25 12:12

Craig