Wordpress - Woocommerece remove “Added to Cart” message

后端 未结 7 572
天命终不由人
天命终不由人 2021-01-18 15:32

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 an

7条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-18 16:24

    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

提交回复
热议问题