Hide ‘add to cart’ button ONLY on woocommerce shop/category pages

I want to hide the button on my shop pages, but I would like to show it on other posts and pages.

I’ve found this code to hide the add to cart button on my whole website:

Read More
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' );
}

How can I tweak it, so it only removes the button on woocommerce shop and catagory pages?

Related posts

Leave a Reply

7 comments

  1. This could also be done with CSS by targeting the relevant classes:

    .cart{display:none;}
    
    .avia_cart_buttons{display:none;}
    

    In my case there is that avia because i use Enfold Theme. With inspect element find out your class where the buton is located. and declare it invisible.

    Another example is:

    .woocommerce .products .shop-column.product-hover-style-2 .product-content 
    .product-add-to-cart-btn{
        display:none !important;
    }
    
  2.     add_action('wp','only_add_bierkoerier_in_cart', 'woocommerce_before_cart');  
    
        function only_add_bierkoerier_in_cart() {
    
        foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
    
    
        $bierkoerier_in_cart = false;
        $categories = get_categories();
    
        if ( has_term( 'bierkoerier', 'product_cat', $cart_item['product_id'] ) ) {
            $bierkoerier_in_cart = true;
            break;
        } 
        }
    
        if($bierkoerier_in_cart) {  
            wc_print_notice( 'omdat u bierkoerier producten in uw winkelwagen heeft 
        kunt u geen winkelitems toevoegen', 'notice' );
           if(is_shop() || is_product() || is_product_category()) {
             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', 30 );
        }
    }
    }
    
  3. To remove the “Add to cart” button
    You need to use hook which not affect other code-

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

    this will remove add to cart button from shop/category pages .

    Here you can get WooCommerce Action and Filter Hook
    https://docs.woothemes.com/wc-apidocs/hook-docs.html

  4. That’s quite simple as i have gone through several tutorials when i was trying to fix it . You have to just put this code in woocommerce.php to hide add to cart button for shop page.

    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();
    }
    

    Hope that would work for you, if not let me know i will guide you

  5. To remove add to cart buttons from shop, product category, and single product pages, use below steps:

    1. Locate the functions.php in child theme. Child theme prevents changes been overwritten by WP updates.
      https://www.dreamhost.com/wordpress/create-woocommerce-child-theme/

    2. Put below code in functions.php:

    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’ );
    }
    }

    add_action( ‘woocommerce_single_product_summary’, ‘woocommerce_before_cart’ );
    function woocommerce_before_cart() {
    if( is_product()) {
    remove_action( ‘woocommerce_single_product_summary’, ‘woocommerce_template_single_add_to_cart’,30);
    }
    }