在WooCommerce购物车页面上取消设置已删除的购物车项目通知 [英] Unset removed cart item notice on WooCommerce cart page

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

问题描述

是否可以隐藏/删除产品已删除.撤消?"通知在购物车页面上,当客户从购物车中删除商品时?

Is there a way to hide/remove the notice "Product removed. Undo?" on the cart page, when the customer removed the item from the cart?

我尝试过:

add_filter( 'woocommerce_cart_item_removed_title', '__return_null' );

但这只会隐藏已被删除的产品标题...

but this only hides the title of the product, that has been removed...

我找不到该行其余部分的正确钩子(已删除"和撤消?")

I couldn't find the right hook of the rest of the line ("removed" and "Undo?")

推荐答案

要在购物车页面上取消设置"{item_name} removed. Undo?"通知,您可以使用以下方法欺骗Woocommerce:

To unset "{item_name} removed. Undo?" notice on cart page, you can trick Woocommerce with the following:

add_action( 'template_redirect', 'null_removed_cart_item_message'  );
function null_removed_cart_item_message() {
    // Only on cart page
    if( ! is_cart() ) return;

    // Get the WC notices array stored in WC_Session
    $wc_notices = (array) WC()->session->get( 'wc_notices' );
    $found      = false; // Initializing

    // Check that we have at least one "success" notice type
    if( isset($wc_notices['success']) && sizeof($wc_notices['success']) ) {
        // Loop through "success" notices type
        foreach( $wc_notices['success'] as $key => $wc_notice ) {
            // Remove notices that contain the word "removed" from the array
            if ( strpos($wc_notice, 'removed') !== false ) {
                unset($wc_notices['success']);
                $found = true;
            }
        }
    }

    if( $found ) {
        // Set back the notices array to WC_Session
        WC()->session->set( 'wc_notices', $wc_notices );
    }
}

代码进入您的活动子主题(或活动主题)的function.php文件中.经过测试,可以正常工作.

Code goes in function.php file of your active child theme (or active theme). Tested and works.

重要提示:根据您的安装语言,您可能需要将功能代码中的已删除"一词更改为方便您使用安装语言的一词.

Important: Depending on your installation language, you could need to change the word "removed" in the function code to the one that is convenient in your installation language.

这篇关于在WooCommerce购物车页面上取消设置已删除的购物车项目通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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