woocommerce 循环中的第一项仍然显示元素

发布于 2025-01-13 01:22:21 字数 916 浏览 2 评论 0原文

我正在尝试删除 Woocommerce“添加到购物车”按钮以及特定产品类别的产品价格 - 我必须开始工作......几乎!

循环中的第一项仍然显示产品价格,请参见屏幕截图。

第一项显示价格

我不太确定为什么?也许我的钩子不太对?

这是我的代码:

//REMOVE ADD TO CART AND PRICE
//removes add to cart buttons and product price on product of 'muslin' category

add_action('woocommerce_after_shop_loop_item_title', 'remove_product_description_add_cart_button' );
function remove_product_description_add_cart_button() { 
    $categories = array('muslins');

    if ( has_term( $categories, 'product_cat', get_the_id() ) ) {
        remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price',10 );
        remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart',10);
    }
}

Im trying to remove Woocommerce 'add to cart' button and the product price on a specific product category - which ive got to work... ALMOST!

The first item in the loop is still showing the product price, see screenshot.

first item shows price

im not really sure why? Perhaps my hook aren't quite right?

here is my code:

//REMOVE ADD TO CART AND PRICE
//removes add to cart buttons and product price on product of 'muslin' category

add_action('woocommerce_after_shop_loop_item_title', 'remove_product_description_add_cart_button' );
function remove_product_description_add_cart_button() { 
    $categories = array('muslins');

    if ( has_term( $categories, 'product_cat', get_the_id() ) ) {
        remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price',10 );
        remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart',10);
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文