2014-01-29 69 views
1

我正在致力于woocommerce主题,我需要隐藏添加到购物车按钮的产品有0作为价格,因为这些产品可能只被询问和未添加到购物车。我已成功隐藏产品页面上的“添加到购物车”按钮,但是,我在商店页面/类别页面上很难做到这一点。WooCommerce隐藏添加到购物车按钮在循环和产品页面

下面是我的代码,用于过滤添加到购物车以及更改默认的“免费”!信息。

add_filter('woocommerce_variable_free_price_html', 'hide_free_price_notice'); 

add_filter('woocommerce_free_price_html',   'hide_free_price_notice'); 

add_filter('woocommerce_variation_free_price_html', 'hide_free_price_notice'); 


/** 
* Changes woocommerce default 'Free!' to return message 
*/ 
function hide_free_price_notice($price) { 
    remove_action('woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 30); 
    remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30); 



    return 'Please inquire for pricing'; 

}

我也试图过滤所有添加到购物车按钮上环,但是这也不能工作。

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'); 

}

有什么建议?我期待看看我是否可以用CSS隐藏它...

回答

0

这是我用来改变'免费!'给'POA'的消息并且隐藏购物车。 注意:在WooCommerce V2.1版本上似乎存在这个问题?

* Swop the 'Free!' price notice and hide the cart with 'POA' in WooCommerce 
*/ 
    add_filter('woocommerce_variable_free_price_html', 'hide_free_price_notice'); 
    add_filter('woocommerce_free_price_html',   'hide_free_price_notice'); 
    add_filter('woocommerce_variation_free_price_html', 'hide_free_price_notice'); 

function hide_free_price_notice($price) { 
    remove_action('woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10); 
    remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30); 
    return 'POA'; 
} 
+0

你把这段代码放在哪里?在functions.php中? –

相关问题