【发布时间】:2021-07-26 14:44:45
【问题描述】:
我有以下钩子工作正常,它确实在结帐页面中添加了删除图标以允许从购物车中删除项目。但是,它确实在购物车页面中隐藏了产品名称。如何使其仅在结帐页面而不在购物车中起作用,或者如何阻止此挂钩在购物车页面中隐藏产品名称?
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;">×</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;
}
}
【问题讨论】:
标签: wordpress woocommerce filter hook