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”.

Read More

Can anyone help me to remove that link?

Text to remove:

Text to remove

Related posts

Leave a Reply

8 comments

  1. 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.

  2. 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>';
    }
    
  3. 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}
    
  4. 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.

  5. 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();