简体   繁体   中英

WooCommerce Hide Add To Cart Button on Loop & Product Page

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.

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...

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM