Woocommerce:从购物车挂钩中删除商品

Woocommerce: Remove item from cart hook

我有以下钩子,它工作正常,它确实在结帐页面中添加了删除图标以允许从购物车中删除项目。但是它确实在购物车页面中隐藏了产品名称。如何让它只在结帐页面而不是购物车中工作,或者如何阻止此挂钩在购物车页面中隐藏产品名称?

add_filter('woocommerce_cart_item_name', 'njengah_filter_wc_cart_item_remove_link', 10, 3);

function njengah_filter_wc_cart_item_remove_link($product_name, $cart_item, $cart_item_key)
{
if (is_checkout()) {
        $product_name .= apply_filters('woocommerce_cart_item_remove_link', sprintf(
        '<a href="%s" rel="nofollow" class="remove" style="float:left;">&times;</a>',
        esc_url(wc_get_cart_remove_url($cart_item_key)),
        __('Remove this item', 'woocommerce'),
        esc_attr($cart_item['product_id']),
        esc_attr($cart_item['data']->get_sku())
        ), $cart_item_key);

        return $product_name;
}
}

使用过滤器时必须return。

add_filter('woocommerce_cart_item_name', 'njengah_filter_wc_cart_item_remove_link', 10, 3);

function njengah_filter_wc_cart_item_remove_link($product_name, $cart_item, $cart_item_key){
    if (is_checkout()) {
        $product_name .= apply_filters('woocommerce_cart_item_remove_link', sprintf(
        '<a href="%s" rel="nofollow" class="remove" style="float:left;">&times;</a>',
        esc_url(wc_get_cart_remove_url($cart_item_key)),
        __('Remove this item', 'woocommerce'),
        esc_attr($cart_item['product_id']),
        esc_attr($cart_item['data']->get_sku())
        ), $cart_item_key);
    }
    return $product_name;
}