• Resolved riew

    (@riew)


    Hi

    In WooCommerce I would like to hide quantity and Add-to-cart button on all list pages (like category) – but NOT on product page.

    If I use:

    
    add_filter( 'woocommerce_is_purchasable', '__return_false');
    

    in my functions.php, it hides it on all pages. But I want to show it on product pages, so I tried something more specific and used this to only target category pages:

    
    function remove_add_to_cart(){
    	 if ( is_product_category() ) {
    	 	add_filter( 'woocommerce_is_purchasable', '__return_false');
    }
    } 
    add_action('woocommerce_single_variation','remove_add_to_cart');
    

    That doesn’t do anything.

    I also tried this:

    
    function remove_add_to_cart(){
    	 
    	 if ( is_product_category() ) {
    	 	add_filter( 'woocommerce_is_purchasable', '__return_false');
    		 // Remove cart from variable products
            remove_action( 'woocommerce_single_variation','woocommerce_single_variation_add_to_cart_button', 20 );
    }
    } 
    add_action('woocommerce_single_variation','remove_add_to_cart');
    

    That works for all variable products, but not for simple products.

    What am I doing wrong…?
    I hope you can help. :o)

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hello @riew ,

    If I understand correctly, you want to hide the “add to cart” or variation selection option from the category archive pages. Is that right?

    You are almost there with your code. You can take this approach instead –

    add_filter('woocommerce_is_purchasable', 'hide_add_to_cart_category', 99 );
    
    function hide_add_to_cart_category ($hide) {
    
    	//short-hand version
    	//return $hide = is_product_category() ? false : true;
    	
    	if ( is_product_category() ) {
    		$hide = false;
    	} else {
    		$hide = true;
    	}
    
    	return $hide;
    }

    I hope you find this useful. Make sure to add this code in your theme’s functions.php file or via a snippet plugin

    Thank you ??

    Thread Starter riew

    (@riew)

    This is perfect – worked like a charm!

    Thank you so much for your fast help! :o)

    Thread Starter riew

    (@riew)

    Marking as closed. Thank you! :o)

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Hide Add-to-cart button on category pages’ is closed to new replies.