My Courses > CustomizeWoo > Module 6 > Lesson 02: Hide Add to Cart

Hide Add to Cart

MARK LESSON AS COMPLETE

You can use this exercise as a test. Stop the video after the project description and see if you can manage to find the PHP solution. Then continue watching the video to watch me code the task.

Video

Please note: English captions are enabled by default (click on “CC” in the video player to disable). Also, you can click on the “gear” icon to manage quality and playback speed. Enjoy!

Sorry, this video is visible to logged in and fully registered students only.
If you already enrolled in this course, please LOG IN
Otherwise, please enroll in the FREE / PRO COURSE
For any other queries, feel free to get in touch

5 thoughts on “Hide Add to Cart

  1. The conditional definitely made this one a little more challenging. Posting this before watching the remainder of the video, to see if I got it right. My code is:

    add_action( 'woocommerce_before_main_content', 'hide_cart_button_if_logged_out' );
    function hide_cart_button_if_logged_out() {
        if ( !is_user_logged_in() ) {
            remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
            remove_action( 'woocommerce_simple_add_to_cart', 'woocommerce_simple_add_to_cart', 30 );
        }
    }
    1. And I have now found out I wasn’t correct… I used the simple_add_to_cart hook, not the single_product_summary one. Oh well. Lesson learned. 🙂

      1. And see that the location where the code is executed also wasn’t quite right. It worked, though… what’s the disadvantage to the one I chose over wp?

        1. Nice work Noelle! There is no difference, as long as the hook you chose loads on the WooCommerce pages you need, and before the remove_action(), so that it’s going to work. In a nutshell: you can use whatever WordPress / WooCommerce / theme hook, as long as it works 🙂

          1. Thanks for letting me know, Rodolfo. Though it was very good to learn about wp.

Questions? Feedback? Support? Leave your comment now!
_____

If you are writing code, please wrap it between: [php]code_here[/php]

Your email address will not be published. Required fields are marked *