Remove/Hide Woocommerce Added to Cart Message but Keep/Display Coupon Applied Message

后端 未结 5 1626
自闭症患者
自闭症患者 2021-01-05 11:12

I\'m trying to remove or hide the added to cart message at the top of my WooCommerce checkout page (I have removed the cart page so this message is showing up on the checkou

相关标签:
5条回答
  • 2021-01-05 11:40

    This should work to hide the product added to cart message

    add_filter( 'wc_add_to_cart_message', 'remove_cart_message' );
    
    function remove_cart_message() {
        return;
    }
    
    0 讨论(0)
  • 2021-01-05 11:41

    Update: 18/05/2018 Please refer to bellmountain's much simpler answer for the correct way to do this.

    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);
    

    Don't worry about using that css you've tried.

    0 讨论(0)
  • 2021-01-05 11:41

    I`m using this:

    add_filter( 'wc_add_to_cart_message_html', '__return_null' );
    
    0 讨论(0)
  • 2021-01-05 11:51

    Just used the following and it worked fine:

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

    Hope this helps!

    0 讨论(0)
  • 2021-01-05 11:59

    this worked for me:

    add_filter( 'wc_add_to_cart_message', 'remove_add_to_cart_message' );
    
    function remove_add_to_cart_message() {
        return;
    }
    
    0 讨论(0)
提交回复
热议问题