Wordpress - Woocommerece remove “Added to Cart” me

2020-04-07 05:00发布

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?

7条回答
祖国的老花朵
2楼-- · 2020-04-07 05:07

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

查看更多
一夜七次
3楼-- · 2020-04-07 05:09

Use one of these:

Older version

$woocommerce->clear_messages(); 

Version 2.3

wc_clear_notices();
查看更多
来,给爷笑一个
4楼-- · 2020-04-07 05:17

Just use simple CSS:

.single-product .woocommerce-message {
display: none !important;
}
查看更多
干净又极端
5楼-- · 2020-04-07 05:17

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

查看更多
唯我独甜
6楼-- · 2020-04-07 05:18

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

查看更多
小情绪 Triste *
7楼-- · 2020-04-07 05:20

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.

查看更多
登录 后发表回答