简体   繁体   English

如何隐藏变量产品的“添加到购物车”,但保持产品变化可见

[英]How to hide 'Add To Cart' for variable products, but keep product variations visible

当我尝试隐藏“添加到购物车”按钮时,变体消失了。

Here is the way to remove add to cart button and quantities in Single product pages for variable products only, keeping the attributes select fields: 这是仅在可变产品中删除“添加到购物车”按钮和“单一产品”页面中数量的方法,并保留属性选择字段:

add_action( 'woocommerce_single_product_summary', 'hide_add_to_cart_button_variable_product', 1, 0 );
function hide_add_to_cart_button_variable_product() {

    // Removing add to cart button and quantities only
    remove_action( 'woocommerce_single_variation', 'woocommerce_single_variation_add_to_cart_button', 20 );
}

Code goes in function.php file of your active child theme (or theme) or also in any plugin file. 代码在您的活动子主题(或主题)的function.php文件中,或者在任何插件文件中。

Tested and works. 经过测试和工作。

I did this, since I have variable products on separate RETAIL pages that I want to keep the 'Add to cart' button 之所以这样做,是因为我在不同的零售页面上有多种产品,我想保留“添加到购物车”按钮

 function remove_add_to_cart(){
    if ( has_term( 'wholesale', 'product_tag' ) ) {

        remove_action( 'woocommerce_single_variation','woocommerce_single_variation_add_to_cart_button', 20 );
}
} 

add_action('woocommerce_single_variation','remove_add_to_cart');

暂无
暂无

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

相关问题 隐藏 Woocommerce 产品变体中特定属性值的添加到购物车按钮 - Hide Add to Cart button in Woocommerce product variations for a specific attribute value WooCommerce AJAX放入购物车以获取可变产品,仍重定向到产品页面 - WooCommerce AJAX Add to Cart for Variable products, still redirecting to product page 隐藏产品价格和添加到购物车按钮,但不包括WooCommerce中未注册用户的变体 - Hide product prices and add-to-cart buttons but not variations for unregistered users in WooCommerce 结帐前需要 WooCommerce 购物车中的简单产品以进行产品变体 - Require simple products in WooCommerce cart for product variations before checkout Woocommerce 隐藏添加到购物车按钮 可变产品除外 - Woocommerce hide add to cart button EXCEPT for variable products 如何仅获取基于 WooCommerce 中特定类别的简单产品和产品变体(不包括可变产品)? - How to get only simple products and product variations (variable products excluded) based on a specific category in WooCommerce? 在“缺货”版本之间切换时,可变产品“添加到购物车”按钮会短暂显示 - Variable product Add to Cart button displays briefly when switching between 'out of stock' variations 如何在不刷新产品列表的情况下将产品添加到购物车? - how can i add products to the cart wihtout refreshing the product list? 隐藏在Woocommerce中变量产品缺货时添加到购物车块 - Hide Add to cart block when a variable product is out of stock in Woocommerce WooCommerce 将多个产品的自定义重定向添加到购物车 - WooCommerce Add to Cart custom redirection for multiple products Variations
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM