如何在woocommerce中隐藏特定消息? [英] How to hide specific messages in woocommerce?

查看:24
本文介绍了如何在woocommerce中隐藏特定消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在不修改基本的 woocommerce 插件的情况下隐藏/删除来自 woo commerce 的特定消息.有几种类型的与优惠券相关的消息,如

i want to hide/remove specific messages from woo commerce without modifying basic woocommerce plugin. There are several types of messages related to coupon like

  1. 优惠券代码已应用!
  2. 对不起!优惠券 12345 已应用于您的购物车.(这里我主要是想隐藏优惠券代码)

以及与这些优惠券代码类似的其他几个.

and several others similar to these coupon codes.

我只想隐藏这些类型的优惠券/购物车消息,其他的都很好,比如产品添加成功!"或任何其他错误消息.

i just want to hide these type of coupon/cart messages, others are fine like "Product successfully added!" or any other error messages.

基本上目的是显示所有其他消息(错误和成功消息),但不想在这些消息中显示优惠券消息和优惠券代码.

Basically the aim is to show all other messages (Error and success messages) but dont wanna show coupon messages and a coupon code in to these messages.

那么,有没有办法通过做任何钩子等来做到这一点,就像我发现的可以消除所有消息字符串的方法(如果我没有错的话).

So, is there any way to do this by doing any hook etc, like one i've found to eliminate all message strings (if i am not wrong).

add_filter( 'woocommerce_coupon_message', '__return_empty_string' );

  1. 还有一件事是,当我将产品添加到汽车中时,一条消息在购物车页面上重复多次.优惠码已经应用!"2,3, 到 4 次.

推荐答案

好的,找到解决方案

转到 woocommerce 模板,复制通知文件夹并编辑所需的模板,在我的例子中是 error.php

go to woocommerce tempaltes, copy notices folder and edit the desired template, in my case its error.php

复制/编辑代码

<ul class="woocommerce-error">
    <?php
     foreach ( $messages as $message ) : 
     if ( $message == "Coupon code already applied!" ) {
            $message = "";//empty error string

        }  else if (strpos($message, 'does not exist!') !== false) {
                $message = ""; //empty error string

            }
           else if (strpos($message, 'Sorry, it seems the coupon') !== false) {
                $message = "";//empty error string

            }
           else if (strpos($message, 'Sorry, this coupon is not applicable to your cart contents') !== false) {
                $message = "Sorry, the discount is not applicable to your cart contents"; //updated error string

            }
    ?> 
        <li><?php echo wp_kses_post( $message ); ?></li>
    <?php
    break;
     endforeach; ?>
</ul>

这篇关于如何在woocommerce中隐藏特定消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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