WooCommerce隐藏添加到购物车按钮循环和产品页面

时间:2021-01-04 20:19:06

I'm working on a woocommerce theme and I'm required to hide the add to cart button for products that have 0 as price, as these products may only be inquired and not added to cart. I have successfully hidden the 'add to cart' button on the product page however, I am having a hard time doing so on the shop page/category page.

我正在研究一个woocommerce主题,我需要为价格为0的产品隐藏“添加到购物车”按钮,因为这些产品可能只会被查询而不会被添加到购物车中。我已经成功隐藏了产品页面上的“添加到购物车”按钮,但是我很难在商店页面/类别页面上这样做。

Below is my code for filtering the add to cart as well as changing the default 'Free!' message.

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

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

}

I have also tried filtering all add to cart buttons on loop, however this did not work either.

我也尝试过滤循环上的所有添加到购物车按钮,但这也不起作用。

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

}

Any suggestions? I'm looking to see if I can hide it with CSS...

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

1 个解决方案

#1


0  

This is what I use to change the 'Free!' message to 'POA' and also hide the cart. Note: There seems to be an issue with this on WooCommerce version V2.1?

这就是我用来改变'免费!'的原因。消息“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';   
}

#1


0  

This is what I use to change the 'Free!' message to 'POA' and also hide the cart. Note: There seems to be an issue with this on WooCommerce version V2.1?

这就是我用来改变'免费!'的原因。消息“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';   
}