简体   繁体   English

在Woocommerce产品类别归档页面上禁用“添加到购物车”按钮

[英]Disable add to cart button on Woocommerce product category archive pages

How can I disable the "add to basket" button for products only on the "categories" page? 如何仅在“类别”页面上禁用产品的“添加到购物篮”按钮?

I still want it visible on the product page. 我仍然希望它在产品页面上可见。

Many thanks 非常感谢

The following will disable add to cart button on product category archive pages: 以下将禁用产品类别归档页面上的“添加到购物车”按钮:

// Disable add to cart on product category archive pages
add_filter( 'woocommerce_is_purchasable', 'disable_purchasable_on_product_category_archives', 10, 2 );
function disable_purchasable_on_product_category_archives( $purchasable, $product ) {
    if( is_product_category() )
        $purchasable = false;

    return $purchasable;
}

Code goes in function.php file of your active child theme (or active theme). 代码进入您的活动子主题(或活动主题)的function.php文件中。 Tested and works. 经过测试和工作。


To target specific product archive pages you will replace use this instead: 要定位特定的产品归档页面,请使用以下代替:

add_filter( 'woocommerce_is_purchasable', 'disable_purchasable_on_product_category_archives', 10, 2 );
function disable_purchasable_on_product_category_archives( $purchasable, $product ) {
    // HERE define your product category terms
    $terms = array( 'shirts', 'games' ); 

    if( is_product_category( $terms ) )
        $purchasable = false;

    return $purchasable;
}

Code goes in function.php file of your active child theme (or active theme). 代码进入您的活动子主题(或活动主题)的function.php文件中。 Tested and works. 经过测试和工作。

See: Woocommerce Conditional Tags 请参阅: Woocommerce条件标签

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为产品类别替换 Woocommerce 单一产品页面上的“添加到购物车”按钮 - Replace Add to cart button on Woocommerce Single Product Pages for a product category 根据 Woocommerce 存档页面中的产品类别更改产品按钮 - Change product button based on product category in Woocommerce archive pages 为 WooCommerce 类别存档页面添加产品标题标签 - Add product title heading tag for WooCommerce category archive pages 在 woocommerce 存档中添加产品类别 - Add Product category in woocommerce archive 如果产品已经在 WooCommerce 购物车中,则禁用添加到购物车按钮 - Disable add to cart button if product is already in WooCommerce cart 如果产品已经在购物车中,则禁用Woocommerce添加到购物车按钮 - Disable Woocommerce add to cart button if the product is already in cart 如何隐藏添加到购物车按钮特定角色和产品类别 Woocommerce - How to hide add to cart button specific role and product category Woocommerce 在WooCommerce中为特定产品类别自定义“添加到购物车”按钮 - Customize “Add to cart” button for a specific product category in WooCommerce 删除 Woocommerce 中特定产品类别的添加购物车按钮 - Remove add cart button in Woocommerce for a specific product category 仅在woocommerce商店/类别页面上隐藏“添加到购物车”按钮 - Hide 'add to cart' button ONLY on woocommerce shop/category pages
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM