2014-11-17 102 views
0

我想隐藏我商店页面上的按钮,但我想在其他帖子和页面上显示它。仅在woocommerce商店/类别页面上隐藏“添加到购物车”按钮

我发现这个代码隐藏添加到购物车按钮,在我的整个网站:

add_action('woocommerce_after_shop_loop_item', 'remove_add_to_cart_buttons', 1); 

function remove_add_to_cart_buttons() { 
    remove_action('woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart'); 
} 

我如何调整它,所以它不仅能消除对woocommerce店铺和产品类别的网页按钮?

回答

4

可以使用Woocommerce条件标签检查: http://docs.woothemes.com/document/conditional-tags/

add_action('woocommerce_after_shop_loop_item', 'remove_add_to_cart_buttons', 1); 

    function remove_add_to_cart_buttons() { 
     if(is_product_category() || is_shop()) { 
     remove_action('woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart'); 
     } 
    } 
+0

THX!这正是我所期待的! – Seb

0

要删除“添加到购物车”按钮您 需要使用挂钩,不影响其他代码 -

add_action('woocommerce_after_shop_loop_item', 'remove_loop_button', 1); 
function remove_loop_button() 
{ 
if(is_product_category() || is_shop()) { 
remove_action('woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart'); 
} 
} 

这将删除从商店/类别页面添加到购物车按钮。

在这里你可以得到WooCommerce行动和过滤钩子 - https://docs.woothemes.com/wc-apidocs/hook-docs.html

-1

你为什么在功能黑客当你有一个简单的方法你去:

.cart{display:none;} 

.avia_cart_buttons{display:none;} 

在我的情况下,有该avia,因为我使用Enfold主题。用检查元素找出你的班级在哪里buton位于。并宣布它不可见。

0

这很简单,因为当我试图修复它时,我经历了几个教程。您必须将此代码放入woocommerce.php以隐藏添加到购物车页面的购物车按钮。

function WpBlog() { 
    remove_action('woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart'); 
    remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart'); 
    return WooCommerce::instance(); 
} 

希望这会为你工作,如果不是让我知道我会引导你

相关问题