2014-11-17 105 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(); 
} 

希望這會爲你工作,如果不是讓我知道我會引導你

相關問題