Wordpress - woocommerce删除"添加到目录"消息


Wordpress - Woocommerece remove "Added to Cart" message

我希望删除的措辞和区域,说"产品成功添加到购物车"后,我向购物车添加一个项目。我只想要什么都没有,没有信息,没有信息的空间。

网址:http://www.tinytreasurehunts.com代码在woocommerce -functions.php

任何想法吗?

要在PHP级别解决这个问题,请将以下模板文件(和结构)添加到您的主题:
/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;

参见:模板结构+通过主题覆盖模板

使用其中之一:

旧版本

$woocommerce->clear_messages(); 

2.3版本
wc_clear_notices();

使用简单的CSS:

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

或者,如果您熟悉functions.php,这是一个更好的解决方案:

add_filter( 'wc_add_to_cart_message_html', '__return_null' );

源代码在这里,如果您希望打印自己的版本,则可以编辑此消息

使用CSS将ID或相关类的显示设置为none

 
.page-id-522 .woocommerce_message {
     display: none;
}

这是特定于页id 522。确保这不会同时隐藏其他有用的消息,如信用卡拒付等。

将此代码添加到themes functions.php文件中。它只会删除该消息。它应该只在可能发生的页面上触发。

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

我已经从我自己的答案中粘贴了这个答案,删除/隐藏Woocommerce添加到购物车消息,但保留/显示优惠券应用消息

WooCommerce Version 2.1.6更新

模板位于新目录和文件中。与上述代码和解决方案相同。

/wp-content/插件/woocommerce/模板/通知/success.php

使用。post .woocommerce_message{display:none;}在主题文件的末尾或子主题中