• Resolved pujsek

    (@pujsek)


    Hello everybody,

    I have some troubles with Woocommerce. I have a store with many products in many different categories. I need products in two of those categories to not display the “Add to cart”. I had some success with different codes but I was unable to get it to work for more than one category and also, every time the code worked, it also removed the product variations.

    Is there a way to remove the “Add to cart” button for multiple product categories and also keep the product variations visible?

    Thank you and best regards, Sa?o.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support Fernando a11n

    (@fhaps)

    Automattic Happiness Engineer

    @pujsek It sounds like you are looking for a code snippet that would enable you to disable cart functionality from a few specific products on your store.

    An option that comes to mind, that doesn’t involve code, would be to set these products to Out of Stock, that way they can’t be purchased. You’ll just have to make sure that out of stock items aren’t configured to be hidden from the store catalog.

    Alternatively, you could use a plugin like Catalog Visibility Options to remove eCommerce functionality from specific products on the store.

    Thread Starter pujsek

    (@pujsek)

    Sadly, setting the products out of stock is not an option, because I need the price to be visible. I used this code:

    function remove_product_description_add_cart_button(){
        global $product;
    
        
        $category = 'categoryslug';
        
        if ( has_term( $category, 'product_cat', $product->id ) )
            remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
    
    }
    add_action('wp','remove_product_description_add_cart_button');

    but it also removes the variations. Is there a way to adapt the code so that the variations stay intact?

    Phil

    (@fullysupportedphil)

    Automattic Happiness Engineer

    Is there a way to adapt the code so that the variations stay intact?

    It’s certainly possible. Given the open nature of both WordPress and WooCommerce, you can write custom code to do almost anything that you want. Our team isn’t able to provide custom code though.

    WooCommerce Developer Slack is a more appropriate place to ask for help with writing code. Otherwise if you need to hire a developer to do this for you, I would recommend checking sites like https://www.codeable.io for skilled third-party developers.

    Plugin Support Fernando a11n

    (@fhaps)

    Automattic Happiness Engineer

    We haven’t heard back from other users in this thread for a while, so I’m going to mark this as resolved – if you have any further questions, you can start a new thread.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Remove Add to cart based on category but preserve variations’ is closed to new replies.