6

I'm looking to remove the wording and area that says "Product Successfully Added to Cart" after I add an item to the cart. I just want there to be nothing, no message and no space for the message.

Here's the site: http://www.tinytreasurehunts.com The code is in woocommerece-functions.php

Any thoughts?

James Jones
  • 3,850
  • 5
  • 25
  • 44
user1803660
  • 81
  • 1
  • 1
  • 3
  • Just remember that when there's an update to WooCommerce if you do it automatically it'll override all your changes. Use it's template system when you can to save yourself the headache of realizing it after the fact. – Anagio Dec 24 '12 at 18:20

7 Answers7

7

To solve this at PHP level, add the following template file (and structure) to your theme:
/wp-content/themes/YOUR-THEME/woocommerce/shop/messages.php:

<?php
/**
 * Show messages
 *
 * @author      brasofilo
 * @package     WooCommerce/Templates
 * @version     1.6.4
 */

if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

if ( ! $messages ) return;

foreach ( $messages as $message ) : 
    // The message does not contain the "add to cart" string, so print the message
    // http://stackoverflow.com/q/4366730/1287812
    if ( strpos( $message, 'added to your cart' ) === false ) :
        ?>
            <div class="woocommerce-message"><?php echo wp_kses_post( $message ); ?></div>
        <?php 
    endif;
endforeach;

See: Template Structure + overriding templates via a theme

brasofilo
  • 25,496
  • 15
  • 91
  • 179
  • 1
    Note that the template structure is now different so yours needs to match it - it is now /wp-content/themes/YOUR-THEME/woocommerce/notices/success.php – Dean_Wilson Oct 12 '14 at 21:19
7

Use one of these:

Older version

$woocommerce->clear_messages(); 

Version 2.3

wc_clear_notices();
eebbesen
  • 5,070
  • 8
  • 48
  • 70
Arni Cinco
  • 71
  • 1
  • 2
4

Just use simple CSS:

.single-product .woocommerce-message {
    display: none !important;
}

Or, if you're familiar with functions.php, this is a better solution:

add_filter( 'wc_add_to_cart_message_html', '__return_null' );

Source is here, together with a way to edit such message in case you wish to print your own version instead

businessbloomer
  • 1,115
  • 7
  • 11
3

Use CSS and set the display to none for the ID or associated class.

 
.page-id-522 .woocommerce_message {
     display: none;
}

This is specific to page id 522. Make sure this doesn't also hide other useful messages like credit card declines, etc.

Kirk
  • 16,182
  • 20
  • 80
  • 112
  • I tried adding that, but don't think it was in the right place. Where do you add CSS for a plugin? – user1803660 Dec 26 '12 at 20:08
  • You'll need to add it and make sure it's below other CSS definitions for those elements. Take a look at the order of precedence for CSS. Also I believe there is a place in Woo themes configuration to add custom CSS. Try there. – Kirk Dec 26 '12 at 22:23
  • I guess it's worth noticing that `522` would be the ID of the *Shop* page. – brasofilo Aug 22 '13 at 14:30
3

Add this code to your themes functions.php file. It will remove only that message. It should trigger on just the pages where it is likely to occur.

function remove_added_to_cart_notice()
{
    $notices = WC()->session->get('wc_notices', array());

    foreach( $notices['success'] as $key => &$notice){
        if( strpos( $notice, 'has been added' ) !== false){
            $added_to_cart_key = $key;
            break;
        }
    }
    unset( $notices['success'][$added_to_cart_key] );

    WC()->session->set('wc_notices', $notices);
}
add_action('woocommerce_before_single_product','remove_added_to_cart_notice',1);
add_action('woocommerce_shortcode_before_product_cat_loop','remove_added_to_cart_notice',1);
add_action('woocommerce_before_shop_loop','remove_added_to_cart_notice',1);

I've pasted this answer from my own answer at Remove/Hide Woocommerce Added to Cart Message but Keep/Display Coupon Applied Message

Community
  • 1
  • 1
James Jones
  • 3,850
  • 5
  • 25
  • 44
1

Update for WooCommerce Version 2.1.6

The template is located in a new directory and file. Same code and solution as above.

/wp-content/plugins/woocommerce/templates/notices/success.php

okimangelo
  • 11
  • 2
0

Use .post .woocommerce_message{display:none;} at the end of your theme files or in your child theme.