Sunita
Sunita

Reputation: 31

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

Upvotes: 3

Views: 30351

Answers (9)

LoicTheAztec
LoicTheAztec

Reputation: 254388

I come very late to the coding "fiesta"…

The following will first hide "view cart" button (via CSS), then with jQuery, I remove it, and remove also "added" class from Ajax add to cart button:

add_action('wp_head', 'ajax_added_to_cart_js', 99999);
function ajax_added_to_cart_js() {
    if( ( is_woocommerce() && ! is_account_page() ) || is_cart() ) :
    // Removing "View cart" button and "added" class.
    wc_enqueue_js("$('body').on('added_to_cart', function(){
        setTimeout( function(){
            $('a.ajax_add_to_cart').each( function(i){
                if ( $(this).hasClass('added') ) {
                    $(this).removeClass('added').parent().find('a.added_to_cart.wc-forward').remove();
                }
            });
        }, 5 );
    });");
    ?>
    <style>.added_to_cart.wc-forward{display:none;}</style>
    <?php endif;
}

Code goes in functions.php file of your child theme (or in a plugin).

Upvotes: 0

Rahul Shinde
Rahul Shinde

Reputation: 1662

This is code for change name of view cart button text and change button URL.

Code goes in function.php file of your active child theme (or theme). Tested and works.

function change_view_cart( $params, $handle )
{
    switch ($handle) {
        case 'wc-add-to-cart':
            $params['i18n_view_cart'] = "Proceed to Cart"; //chnage Name of view cart button
            $params['cart_url'] = "http://shop.com/cart"; //change URL of view cart button
        break;
    }
    return $params;
}
add_filter( 'woocommerce_get_script_data', 'change_view_cart',10,2 );

Please do not change any code into the add-to-cart.js file. Otherwise its not work.

Any help would be greatly appreciated.

Upvotes: 2

Stephen
Stephen

Reputation: 1

Sorry for not having explanation. Add to functions.php the following lines

add_action( 'wp_footer', 'no_view_cart' );
function no_view_cart() {
?>
<script type="text/javascript">
jQuery( function($){

    $(document.body).on( 'added_to_cart', function( event, fragments, cart_hash, $button ) {
        $.ajax({
                type: 'POST',
                url: wc_add_to_cart_params.ajax_url,
                data: {
                    'action': 'checking_items',
                    'id'    : $button.data( 'product_id' )
                },
                success: function (response) {

                    $button.removeClass( 'added' );
                    $button.parent().find( '.added_to_cart' ).remove();

                }
            });
        });
    });
</script>
<?php
}

Other thing not related to this OP question. If you want to remove the "View Cart" button after item(s) has been removed from mini cart, you can add another jQuery function, but this should not be placed in no_view_cart() function:

$('.button[data-product_id="' + product_id + '"]').removeClass( 'added' );
$('.button[data-product_id="' + product_id + '"]').parent().find( '.added_to_cart' ).remove();

Upvotes: 0

If you want to keep the "Add To Cart" button and remove the "View Basket"

// Makes "Add to Cart" button visible again
.add_to_cart_button.added  {display:  inline-block}
// Removes "View Basket"
.added_to_cart.wc-forward {display: none}

Upvotes: 2

Craig
Craig

Reputation: 2153

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

a.added_to_cart {display:none !important}

Upvotes: 6

Davoud
Davoud

Reputation: 2993

Adding this to style.css in child theme worked for me.

body .dhvc-woo-addtocart a.added_to_cart {
    display: none;
}

Upvotes: 0

indextwo
indextwo

Reputation: 5935

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.

Upvotes: 8

user6324077
user6324077

Reputation:

I think this may be useful.

Just add this code in css.

a.added_to_cart.wc-forward {display:none}

Upvotes: 5

Amin.T
Amin.T

Reputation: 198

That will do the job (but its not the ideal solution)

// Removes Product Successfully Added to Cart
// Woocommerce 2.1+

add_filter( 'wc_add_to_cart_message', 'wc_custom_add_to_cart_message' );

function wc_custom_add_to_cart_message() {
    echo '<style>.woocommerce-message {display: none !important;}</style>';
}

Upvotes: 2

Related Questions