Wordpress - Woocommerece remove “Added to Cart” message

后端 未结 7 573
天命终不由人
天命终不由人 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:15

    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.

    0 讨论(0)
  • 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

    0 讨论(0)
  • 2021-01-18 16:27

    Just use simple CSS:

    .single-product .woocommerce-message {
    display: none !important;
    }
    
    0 讨论(0)
  • 2021-01-18 16:29

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

    0 讨论(0)
  • 2021-01-18 16:31

    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

    0 讨论(0)
  • 2021-01-18 16:39

    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

    0 讨论(0)
提交回复
热议问题