WooCommerce-未设置的< product>已删除的通知..."在购物车页面 [英] WooCommerce - unset "<product> removed notice…" on cart page

查看:71
本文介绍了WooCommerce-未设置的< product>已删除的通知..."在购物车页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

动作和过滤器.当我从购物车中删除产品时,在WooCommerce网站上会收到以下消息:

actions and filters. On my WooCommerce site I get the following message when I remove a product from the shopping cart:

"<product name>" removed. Undo?

查看WooCommerce源代码,我在class-wc-form-header.php中发现了一条条件语句,该条件语句是函数 update_cart_action() 的一部分:

Looking over WooCommerce source code I have found a conditional statement in class-wc-form-header.php as part of the function update_cart_action():

$removed_notice .= ' <a href="' . esc_url( WC()->cart->get_undo_url( $cart_item_key ) ) . '">' . __( 'Undo?', 'woocommerce' ) . '</a>';

但是我找不到找到消除此通知的方法.我尝试使用CSS解决方案,但没有成功:

But I can't find the way to use it for eliminate this notice. I have try css solutions but it didn't work:

PS:那也许不是困扰我的代码片段,但它是我发现的唯一有意义的代码.

PS: that may not be the code snippet that is bothering me, but its the only one I have found that seems to make sense.

如何删除此烦人的通知?

How can I remove this bothering notice?

谢谢.

推荐答案

您可以通过不同的方式做到这一点:

You can do that in different ways:

1.覆盖notices.php模板:
您首先要(如果尚未完成)将woocommerce templates 文件夹复制到活动子主题或主题中,然后将其重命名为 woocommerce >.然后打开/编辑notices/notices.php并尝试替换代码:

1. Overriding the notices.php template:
You have first (if not done yet) to copy woocommerce templates folder inside your active child theme or theme, then rename it woocommerce. Then open/edit notices/notices.php and try to replace the code:

<?php
/**
 * Show messages
 * ... Blabla ... / ... blabla ...
 * @version     1.6.4
 */

if ( ! defined( 'ABSPATH' ) ) {
    exit; // Exit if accessed directly
}

if ( ! $messages ){
    return;
}

?>

<?php foreach ( $messages as $message ) : // Change your template code from here
    if ( strpos( $message, 'removed' ) === false ) : ?>
    <div class="woocommerce-info"><?php echo wp_kses_post( $message ); ?></div>
<?php endif;
endforeach; ?>

2.使用挂钩:

function remove_added_to_cart_notice()
{
    $notices = WC()->session->get('wc_notices', array());

    foreach( $notices['notices'] as $key => &$notice){
        if( strpos( $notice, 'removed' ) !== false){
            $added_to_cart_key = $key;
            break;
        }
    }
    unset( $notices['notices'][$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);

3.使用CSS (类似):

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

参考:

  • Wordpress - Woocommerece remove "Added to Cart" message
  • New wc-notice-functions.php on github

这篇关于WooCommerce-未设置的&lt; product&gt;已删除的通知..."在购物车页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆