[英]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.