在WooCommerce购物车页面上未设置已删除购物车项目的通知

问题描述 投票:1回答:2

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

我尝试过:

add_filter( 'woocommerce_cart_item_removed_title', '__return_null' );

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

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

php wordpress woocommerce cart notice
2个回答
1
投票

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

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文件。经过测试,可以正常工作。

重要:根据您的安装语言,您可能需要将功能代码中的“已删除”一词更改为您的安装语言中最方便的一种。


0
投票

我有相同的问题,使用以下语句解决:

add_filter('woocommerce_cart_item_removed_notice_type', '__return_null');

代码进入您的活动子主题(或活动主题)的function.php文件。

© www.soinside.com 2019 - 2024. All rights reserved.