skip to Main Content

How to hide ONLY this notification "You cannot add another (product) to your cart" from woocommerce with CSS? If I use this CSS code then all notifications are hidden but other notifications are useful.

ul.woocommerce-error,.page-id-6 .woocommerce-notices-wrapper {
    display: none;
}

2

Answers


  1. Unfortunately, it is not possible to apply such logic with the sole help of the CSS.

    Login or Signup to reply.
  2. /*
    * this code may help to unset specific notice
    */
    
    function remove_added_to_cart_notice()
    {
        $notices = WC()->session->get('wc_notices', array());
    
        foreach( $notices['success'] as $key => &$notice){
            if( strpos( $notice, 'You cannot add another (product) to your cart' ) !== 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);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search