WooCommerce: Hide Price & Add to Cart for Logged Out Users

You may want to force users to login in order to see prices and add products to cart. That means you must hide add to cart buttons and prices on the Shop and Single Product pages when a user is logged out.

All you need is pasting the following code in your functions.php (please note: your theme may have overwritten some default WooCommerce functions, hence the code below may not work. Contact me if you need custom code). Enjoy!

woocommerce-hide-prices-add-cart-shop-single-product
WooCommerce: Hide Price & Add to Cart to Logged Out Users

PHP Snippet: Hide Add to Cart Buttons and Prices if Logged Out @ WooCommerce Shop, Single Product Pages, Widgets, etc.

/**
 * @snippet       Hide Price & Add to Cart for Logged Out Users
 * @how-to        businessbloomer.com/woocommerce-customization
 * @author        Rodolfo Melogli, Business Bloomer, BusinessBloomer.com
 * @testedwith    WooCommerce 7
 * @community     https://businessbloomer.com/club/
 */
 
add_filter( 'woocommerce_get_price_html', 'bbloomer_hide_price_addcart_not_logged_in', 9999, 2 );

function bbloomer_hide_price_addcart_not_logged_in( $price, $product ) {
	if ( ! is_user_logged_in() ) { 
		$price = '<div><a href="' . get_permalink( wc_get_page_id( 'myaccount' ) ) . '">' . __( 'Login to see prices', 'bbloomer' ) . '</a></div>';
		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 );
      add_filter( 'woocommerce_is_purchasable', '__return_false' );
	}
	return $price;
}

Where to add custom code?

You should place custom PHP in functions.php and custom CSS in style.css of your child theme: where to place WooCommerce customization?

This code still works, unless you report otherwise. To exclude conflicts, temporarily switch to the Storefront theme, disable all plugins except WooCommerce, and test the snippet again: WooCommerce troubleshooting 101

Related content

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza. Follow @rmelogli

401 thoughts on “WooCommerce: Hide Price & Add to Cart for Logged Out Users

  1. Thanks – works perfectly.

    I did change it to “Log in to see prices”. “Log in” is the verb so is correct. Login is a noun so is incorrect English.

  2. Hi
    Great post
    Is there anyway of doing this but keeping the product availability? Changing the purchasable to false removes the is available block too.
    Thanks

    1. Hi Chris, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  3. This worked perfectly. Thanks so much.

      1. Hello Rodolfo,
        first of all u have a great code 🙂
        this works perfect on my test- page but my variable product does still shows the price, even if the user not logged.
        Do u have any idea, how we can fix this? 🙂

        https://postimg.cc/G8JWtNwr

        Regards,
        Tufan

        1. Hello Tufan, this works for all product types. So, there is something related to your variable products that is not letting the script trigger. It could be a custom theme function, or a plugin – try to temporarily switch to Storefront theme, disable all plugins except Woo, and then test the snippet again

      2. For some reason this broke recently on one of our sites.

        1. Only on one? Because the script is still valid, so maybe it’s because of a conflicting plugin/theme (just guessing)?

  4. Hello Rodolfo,
    Thank you for this bit of code.
    I have one issue only and that is that on the product archive page, a savvy user can add “?add-to-cart=xxx” with the product ID and still seem to get to buy a product. Is there a way to block that?
    Cheers,
    Kitka

    1. I’ve added a new line, can you please test this new version?

  5. Hi, what would be the code so that after logging in I would return to the page where I was before, the product page

    1. Hi Max, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  6. Hi,
    Thank you for this code, this is very useful!
    I’m using Polylang Pro (website in EN and FR) and I was wondering how to translate the “Login to see prices” message.
    I’m looking for the same translation solution for this message in Add to Cart Button : https://www.businessbloomer.com/woocommerce-rename-add-to-cart-button-if-product-already-cart/

    Can you tell me how to replace the messages with a string I can edit?
    Thank you in advance for your help.
    Best Regards,
    Renaud

    1. Hey Renaud, thanks for your comment! In order to make a string translatable you have to wrap it in a __() function: https://codex.wordpress.org/I18n_for_WordPress_Developers#Translatable_strings – hope this helps 🙂

  7. I have this code installed on my website I am working on. But it doesn’t seem to work with Elementor Pro plugin. Should it work with the Pro plugin?

    1. Hi Tony, thanks for your feedback. Not sure what Elementor PRO does, but this snippet works with default WooCommerce and hasn’t been tested with all possible themes and page builders

  8. Hi,
    I like your solution. But there is one nuance. Some plugins, (like Dokan or Xforwoocommerce) add their own buttons to the product page, which are tied to the cart (like the live chat button and the support button or selector button). Your code removes the cart and along with it the buttons added by other plugins disappear. Is there a solution that won’t affect other buttons?

    1. Hello Renat thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  9. Hi,
    THanks for the great code.
    Although this may hide the add to cart button, users can still add an item to cart by going to http://www.example.com/?add-to-cart=25
    How would you prevent logged out users from adding items to cart completely?
    Many thanks,

  10. hi

    code works fine at the startpage with all products

    but not at the detail page – there i can see the prices (variable products)

    1. Hi Joerg, you probably have a custom theme or a plugin that is altering WooCommerce default hooks. So, yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  11. Hi, the code still works in general. Only not for the products in the widgets. I’m using the Flatsome theme. The website I’m developing is in development.

    Would be great if you could add a piece of code to hide the prices in these widgets as well. Thanks!

    1. Try with this new version

  12. Hi there!

    Nice snippet!!!! Just one question, is it possible to change a link for a button???

    Thank you in advanced.

    1. Cheers, yes that’s possible

  13. Hello,
    thank you for your time to write this code and help us.

    I used it on a website with The7 theme and WordPress 5.7

    It hides the Add to Cart button but it doesn’t hide the price.
    Can you help?

    https://ibb.co/1fCTsLw
    https://ibb.co/sWGDPLx

    1. Hi Moridin, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  14. WordPress 5.7 freshly updated, woocommerce 5.1 freshly updated, your snippet still works flawlessly.
    All hats off, Rodolfo, your site has really helped me a lot in my work !

  15. Hi, thank you for the codes. It works for product pages where I have product with one price. However, where I have a product with different price depending on the selected specifications, the hide price if not logged in function does not work. Please advise.

    1. Thanks Elyn! Can I have a screenshot please?

      1. I see, so that’s for a variable product. It works perfectly for me on a default theme. Maybe your own is customized?

  16. Hi,

    Thanks for the code but unfortunately this code doesn’t work on Product Quick view on Flatsome theme rest it works fine. Can you please help me to fix that too it will be really great for me.

    Thanks

    1. Hi Harendra, thanks so much for your comment! I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  17. Due to the new update some time ago of storefront etc., there is an additional problem which still enables not logined users to see the prices – When we are on particular product page and scroll down to the product details, on the top there would appear a bar with the information what product we are viewing and the price of it and the button to add that product to the cart.
    I guess we just need to add one more line to our code, but it’s above my skills to find what is the name of the code responsible for that.
    Thanks

    1. Hello Asda, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  18. Is there a code for hiding variants for non registered users?

    1. Hi Chris, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  19. It’s not working on Astra Theme.

    Still see the add to cart button

    1. Ask Astra support

  20. Bonjour, merci pour votre code, mais cela ne fonctionne pas sur les pages produits. Merci pour votre aide

    1. Works on Storefront theme, so probably you have a custom theme and you may need a different workaround

      1. Avez-vous une solution à me proposer afin que cela fonctionne. Merci

        1. Sebastien, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  21. Thanks for this code
    How to disable this code for External products
    And how do I disable this code for a product ?
    And be transferred to a id products or url ?
    Thank

    1. Hi Ehsan, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  22. Hello Rodolfo,

    Your snippet works great in terms of removing price and cart features from lists and products. Thank you so much for this.
    I have a big problem though: It does not hide prices from Google (and maybe other search engines). Anyone who searches my products from google images can unfortunately find the prices. I would be grateful if you could post a hint!

    Thank you so much for your time and effort!

    1. Hi Tasos, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  23. Hi Rodolfo
    Thanks for your snippet. I installed it successfully but I have 1 simple question. What is the CSS code to make the layout center for the text? The product name already set center in the box so I want to make this center too.
    Also, is there any code for redirecting after login? For Example, after login goes to new arrival page.
    Thank you so much.

    1. Hi Alex, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  24. Its not removing the it from product single page. How can I do that please?
    Thanks!

    1. Disable all plugins and switch to 2020 theme, does this work?

  25. Hello there,
    First of all I would like to thank you very much.
    1 – When I use this code, if the sidebar is active, we can see the price of the product there. So the product price is not hidden in the sidebar.
    2- How can I solve that the button created when I add the code has a design compatible with the theme? Or what should I follow if I want to design it myself?
    Best regards

    1. Hi Wnet, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  26. Hi,

    I want the Product Image links to be changed same link how the add to cart button for non-logged in users.
    Please help!

    1. Hey Vinayak, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  27. I can’t get it to work with my Astra Theme, I got the single product page to work, but I can’t seem to remove it from the shop page itself,

     add_action( 'init', 'shessvy_hide_price_add_cart_not_logged_in' );
    
    function shessvy_hide_price_add_cart_not_logged_in() {
        if ( ! is_user_logged_in() ) {
            remove_action( 'astra_edd_archive_add_to_cart', 'astra_edd_archive_product_add_to_cart');
    
            remove_action( 'woocommerce_simple_add_to_cart', 'woocommerce_simple_add_to_cart', 30 );
            remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
            remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
            remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
    
            add_action( 'woocommerce_single_product_summary', 'shessvy_print_login_to_see', 31 );
            add_action( 'woocommerce_after_shop_loop_item', 'shessvy_print_login_to_see', 11 );
            add_action( 'woocommerce_simple_add_to_cart', 'shessvy_print_login_to_see', 30 );
        }
    }
    
    function shessvy_print_login_to_see() {
        echo '<a href="' . get_permalink(wc_get_page_id('myaccount')) . '" rel="nofollow ugc">' . __('Login to see prices', 'theme_name') . '</a>';
    }
    

    I guess I need to reach out to Astra because the code worked with another theme of mine, so I am like arrr.. almost had it.

    1. However, after researching WooCommerce more I found [woocommerce_is_purchasable]

      which make this code much more efficient for anyone who wants to use it, here it is

      
      //this will remove add to cart button and add a read more button to all products in the cart. and remove the add to cart everywhere. 
      // only for logged out users 
      
      add_action( 'init', 'shessvy_hide_price_add_cart_not_logged_in' );
      
      function shessvy_hide_price_add_cart_not_logged_in() {
          if ( ! is_user_logged_in() ) {
      
              add_filter( 'woocommerce_is_purchasable', '__return_false');
      
              add_action( 'woocommerce_single_product_summary', 'shessvy_print_login_to_see', 31 );
              add_action( 'woocommerce_after_shop_loop_item', 'shessvy_print_login_to_see', 11 );
              add_action( 'woocommerce_simple_add_to_cart', 'shessvy_print_login_to_see', 30 );
          }
      }
      
      function shessvy_print_login_to_see() {
          echo '<a href="' . get_permalink(wc_get_page_id('myaccount')) . '" rel="nofollow ugc">' . __('Login to see prices', 'theme_name') . '</a>';
      }
      
      
      1. Nice!

        1. Thank you Radalfo, very useful snippet! I appreciate your effort!
          I would like to know if it possible to make this snippet work only for particular category of products?

          1. Rafa, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  28. Code works great! However, I’d like to place the “Login For Price” text where the price would be on the page vs where the add to cart is. What code do I need to edit/add for that?

    1. Hi there, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  29. Still works even after we upgrade our wordpress version. But then I decided to have my on-sale products to have their prices and to allow purchase even if user is logged out, it returned an error.

    I tried adding this code.
    if ( $product->is_on_sale() ) {
    add_action( ‘woocommerce_single_product_summary’, ‘customAttr’, 31 );
    add_action( ‘woocommerce_before_single_product’, ‘check_if_variable_first’ );
    add_action( ‘woocommerce_single_product_summary’, ‘custom_wc_template_single_price’, 10 );
    }

    1. Raymund, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  30. Hello, your code still work , great
    could you please to update also how to include to hide price and add to cart button on a sticky add to cart on the header of storefront themes. there is still appear there

    thank you

    1. Nyampah, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  31. Hi, Tyryed this with Elementor Hello theme ad Elementor Child. Does not work at all..

    1. If they override WooCommerce this won’t work unfortunately, it needs to be customized

  32. did not work on single product page
    scroll to the bottom and the add to cart will be displayed at the top of the page as in url above

    You’re viewing: Lowepro Slingshot Edge 250 AW
    £109.95 Add to cart

    1. Hi there – that’s a theme-specific banner that is not default WooCommerce. So you need to add another remove_action that targets this custom functionality. I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  33. Hello,
    great and thank you, your code work well on product, category and single page

    since im so blind with wordpress and php so i just combined it with css to also hide the price on product sidebar widget
    .product_list_widget li .woocommerce-Price-amount {
    display:none;
    }

    do you have an idea also how to hide price on sidebar for non logged in user ?

    1. Hey Morgan, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  34. Hi!

    Worked grate! But i have a little problem… I use “Product Blocks” on the front page and some other pages, but the price and buttons still showing there. (I use Storefront Theme‎)

    1. Maybe instead of blocks try with the official WooCommerce shortcodes?

  35. still works, Feb 2020.. with latest wordpress and woocommerce. Thank you

    1. Thank you!

  36. hello Friend,

    I implemented your code to my child theme.

    but it is now 2 buttons active. Add to cart and login to see price both are active. what should I do now?

    1. Please read previous comments – it could be due to your custom theme

  37. Thanks for the code it works for us except single product page it is not hiding add to cart button

    1. Hi Harendra, thanks for your comment! I just tested this again with Storefront theme and it works perfectly. Maybe your theme (or another plugin) is messing/conflicting with my snippet?

      To troubleshoot, disable all plugins but WooCommerce and also switch temporarily to “Twentyseventeen” theme (load the snippet there in functions.php) – does it work? If yes, you have a problem with your current theme or one of the plugins.

      Hope this helps!

      R

  38. Hello, first of all thank you, this worked.
    secondly, is there a way to make the ” login to see the prices” in a box or in bold letters?

    Thank you

    1. Hi Ajmal, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  39. Can you mention additional code to hide the price on the Sensei LMS Search course page and the Single course page as well. I am using Skilled theme with Sensei LMS using Woo-commerce to sell the courses.

    1. Hey Ash, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  40. Hello awesome snippet!!! But is it possible to centered the Login text?
    Thanks
    Joe

    1. Hi Joe, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  41. Hi there, I’m getting an error code:

    PHP Warning: call_user_func_array() expects parameter 1 to be a valid callback, function ‘bbloomer_print_login_to_see’ not found or invalid function name in /home/*/public_html/wp-includes/class-wp-hook.php on line 288

    Using WP 5.3 and Woocommerce 3.8

    Can you help?
    Thanks

    1. Did you copy the whole snippet? Seems you’re missing the final function

    2. Hi I have copied the snippet and it shows login for price but the price is still showing above it ???
      I am using WP 5.3 , I am no developer but need customers to be logged in to see wholesale price.

      Thanks

      1. Hi Estephan, thanks for your comment! I just tested this again with Storefront theme and it works perfectly. Maybe your theme (or another plugin) is messing/conflicting with my snippet?

        To troubleshoot, disable all plugins but WooCommerce and also switch temporarily to “Twentyseventeen” theme (load the snippet there in functions.php) – does it work? If yes, you have a problem with your current theme or one of the plugins.

        Hope this helps!

        R

  42. Awesome snippet!!! Does this also works on variable products? Simple products, there’s no problem, but I am seeing prices for variable products.

    1. Hi Raymund, yes it should. Can you try with a different theme first?

      1. Hey Rodolfo,thanks for the tips! I have also experienced a similar problem(prices remain hidden for me so that is ok) and I tried to trouble shoot it by activating the basic wordpress themes and using the snippet and there seems to be a problem with variable products. Suddenly the selectable options disappear when using the snippet. Can you confirm the same? I suspect hidden prices affect variable products?

        1. Hi Bill, the snippet will hide add to cart buttons, therefore this includes the variable product dropdowns

  43. Hello!

    I try to do following.
    – Hide price for specific category when logged out.
    – When logged in the price of that category is visible

    What is wrong with this code?

    add_action( 'init', 'bbloomer_hide_price_add_cart_not_logged_in' );
      
    function bbloomer_hide_price_add_cart_not_logged_in() {   
    if ( ! is_user_logged_in() ) {      
     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 );
     remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
     remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );   
     add_action( 'woocommerce_single_product_summary', 'bbloomer_print_login_to_see', 31 );
     add_action( 'woocommerce_after_shop_loop_item', 'bbloomer_print_login_to_see', 11 );
    }
    }
    if ( has_term( 'GRATiAE', 'product_cat' ) ) {
    function bbloomer_print_login_to_see() {
    echo '<a href="' . get_permalink(wc_get_page_id('myaccount')) . '" rel="nofollow">' . __('Login to see prices', 'flatsome') . '</a>';
    }
    }
    
    1. Hi Daniil try putting has_term() inside the function and not outside

  44. This can also be done with simple css. First you’ll need to find the class you want to hide when logged out. You can do this by right clicking the cart icon and inspect element. Now that you have the class you can add this css to your additional css in customize or to your style.css file.

    body:not(.logged-in) .nav-link-cart {
    display: none !important;
    }

    The above is an example with my class added to the css. In this case my class is “nav-link-cart”.
    Simply just replace “nav-link-cart” with your own class. Easy work 🙂

  45. Hey,

    I would like to force customers to login to view single product pages or when they try to view the cart but still be able to view all other pages – is this something which is possible? would it be similar to the code on this page?

    1. Hello Nathan, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

    2. Hi Nathan. I think you may be looking for a plugin like Conditional Menus by Themify. Or maybe I understood your question wrong haha.

  46. Hello Rodolfo,

    I just tried the code but it didn’t work and it was copied directly into the functions.php

    1. Adeola, thanks for your comment! I just tested this again with Storefront theme and it works perfectly. Maybe your theme (or another plugin) is messing/conflicting with my snippet?

      To troubleshoot, disable all plugins but WooCommerce and also switch temporarily to “Twentyseventeen” theme (load the snippet there in functions.php) – does it work? If yes, you have a problem with your current theme or one of the plugins.

      Hope this helps!

      R

      1. Hello. I have used this code as well. Done troubleshooting (deactivate all plugins except woocommerce and used themes like twentyseventeen and storefront) — still not working. What’s the other workaround please?

        1. Works for me perfectly on latest Storefront, WooCommerce and WordPress – not sure 🙂

  47. dude you are great it works with be theme Thanks alot!

    1. Cool!

  48. As of newest Woo Commerce this code it is not working. Woo Commerce 3.7.8, multiple websites. Tried with Twenty Nineteen theme too, not working. Please can you take a look at it.

    1. I don’t see why it shouldn’t work 🙂 Tried with no plugin but Woo?

  49. This code not working in wordpress+woocommerce 3.6+Divi theme.
    Solution?

    1. Hola Pedro, thanks for your comment! I just tested this again with Storefront theme and it works perfectly. Maybe your theme (or another plugin) is messing/conflicting with my snippet?

      To troubleshoot, disable all plugins but WooCommerce and also switch temporarily to “Twentyseventeen” theme (load the snippet there in functions.php) – does it work? If yes, you have a problem with your current theme or one of the plugins.

      Hope this helps!

      R

  50. Hi! Could this be done for specific user roles? Thanks in advance

    1. Hi Marcial, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  51. Hello,

    Is it possible to make the text wrapped as a button? It would be better from an UE perspective.

    Kind regards,
    Petar

    1. Hi Petar, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  52. I see you revised this code in May 2019. Your code states it @compatible WooCommerce 3.6.2.

    I am currently installing Version 5.2.1

    Is your code compatible with the most recent version of WP?

    1. Yes of course

  53. Hi Rodolfo Melogli,

    Your work is appreciated, but I have a problem, I am using Pecil theme. I add your code in functions.php file, I don’t have child theme. but it just hiding Prices but not add to cart button from product pages before login. I tried on default theme too but no change. So please can you guide me what I need to do for hiding add to cart button before login. I am looking forward for your response.

    Best Regards,
    Raj

    1. Hi Raj, thanks so much for your comment! I just retested this on the latest version of WooCommerce and it still works. Unfortunately this looks like custom troubleshooting work and I cannot help here via the blog comments. Thanks a lot for your understanding! ~R

  54. Hi,
    This code was working fine for a year but Now today its not working on only one product category page, it is working on rest of the pages. Dont know what to do , can you help?

    1. Hello Ajay, thanks for your comment! I just tested this again with Storefront theme and it works perfectly. Maybe your theme (or another plugin) is messing/conflicting with my snippet?

      To troubleshoot, disable all plugins but WooCommerce and also switch temporarily to “Twentyseventeen” theme (load the snippet there in functions.php) – does it work? If yes, you have a problem with your current theme or one of the plugins.

      Hope this helps!

      R

  55. Hi, for me is working, for visitors, but google is showing prices in his images directory in mobiles phones.

    How can I fix that, because, is a very big problem.

    1. Hello Adriana, thanks so much for your comment! Yes, this is possible – unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

  56. Unfortunately code is not working for me in a brand new fresh WordPress install. I can still see prices although it says “login to see prices” below the price. Here’s my setup:

    WordPress 5.0.3
    Woocommerce 3.5.4
    PHP 7

    1. Hey Ed, thanks for your comment! Can you try switching temporarily to “Twentyseventeen” or “Storefront” theme and let me know if it works?

  57. TYVM!! This works great 2/5/2019

    1. Cool!

  58. Hi Rodolfo,

    I have a similar issue to the one Felix has, when I activate the plug in I get:

    Warning: session_start(): Cannot send session cache limiter – headers already sent (output started at wp-content/plugins/hide-price-until-login/includes/hide-price-until-login-class.php:540) in wp-content/plugins/hide-price-until-login/includes/main.php on line 7

    Warning: Cannot modify header information – headers already sent by (output started at wp-content/plugins/hide-price-until-login/includes/hide-price-until-login-class.php:540) in wp-admin/includes/misc.php on line 1126

    Not sure what to do…
    thanks for your help
    Annelie

    1. Hey Annelie, thanks for your comment. You’re using another plugin, and that does not relate to my snippet 🙂

  59. Thanks a lot! It still works in 2018 with Divi theme, Woocommerce and Ultimate Member.
    I was using a plugin to hide the price (called ‘Hide Price Until Login’ by CedCommerce) but it gave me some white screens of death, so I had to delete it. And then I found your piece of code and it works great.

    1. Awesome 🙂

  60. Hi Rodolfo,

    the snippet worked perfectly until a few days ago. I think it might be the woocommerce update 3.4.7 where something went wrong.
    Just to let you know, and perhaps you might be able to fix it 😉

    Thanks a lot,

    Georg

    1. Georg, thanks for your comment! I don’t see 3.4.7 changes that might affect this snippet. Can you try with another theme please?

  61. Is there any way to make this snippet work with YITH WooCommerce Wishlist as well? This works perfectly with hiding pricing but users are able to click add to wishlist then see the pricing in that screen.

    1. Dear Ben – thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding! ~R

  62. Hi, Rodolfo. I’am using your snippet, but I use also plugin “Variations to Table – Grid”. Effect: The price of the main product is hidden, but in the table of variable products prices are still visible. How to hide prices in the table of variable products until login? How to modify your snippet? Is this possible?

    1. Hello Maciej, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding! ~R

  63. Hi Rodolfo.
    I am using this snippet and it worked great after the set up a year ago. But now logged in customers can no longer see the Buy button or cart, they only get the “Login to see the price”. This problem also appears with latest version of WC. I made a test order in an incognito window before updating WC, and it is still there.
    I also use your snippet for privacy policy (https://businessbloomer.com/?p=19854). Do they conflict?
    Best regards

    1. Hello Johan! No, they should not conflict – but if you want to test this feel free to disable the privacy snippet and see if the error goes away. In regard to this snippet, it is still valid and it works. Maybe something changed in your theme – can you try to switch theme temporarily to see if the snippet works with e.g. 2017 theme?

  64. Hi Rodolfo,

    I implemented this super nice piece of code, sadly it doesn’t hide my button on the Shop loop. I didn’t use many snippets yet and tried to turn some things around like setting the final value to 50 to see if it had any effect, without success.
    Let’s also mention that I use the clever Code snippets plugin to do the hard job without braking my site.

    Do you have a quick fix idea ?

    1. Hi Rodolfo, I finally found the issue. Since I use the Divi theme & builder I had to add a specific snippet to allow Woocommerce to display its “add to cart” button. It’s a shame we have to add this (non given) snippet while seeing that it even bring some limitations as this one.

      Here is the snippet in question :

      function dac_add_cart_button ()
      {
          add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_add_to_cart', 10 );
      }
      add_action( 'after_setup_theme', 'dac_add_cart_button' );
      

      Here is the modified version to work only for logged-in users :

      // register add to cart action
      function dac_add_cart_button ()
      {
       	if ( is_user_logged_in() )
      	{
          add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_add_to_cart', 10 );
      	}
      }
      add_action( 'after_setup_theme', 'dac_add_cart_button' );
      

      Removing the dedicated code as this :

      /* Hide Price &amp; Add to Cart for LOGGED OUT USERS + show text :  "Login to see prices" */
      
      add_action( 'init' , 'woo_hide_price_and_button_not_logged_in' ); 
      function woo_hide_price_and_button_not_logged_in()
      {
      	if ( !is_user_logged_in() )
      	{
      //	remove_action( 'woocommerce_single_product_summary' , 'woocommerce_template_single_add_to_cart' , 30 );  Related to Divi button setup php
      	remove_action( 'woocommerce_single_product_summary' , 'woocommerce_template_single_price' , 10 );
      	remove_action( 'woocommerce_after_shop_loop_item' , 'woocommerce_template_loop_add_to_cart' , 10 );
      	remove_action( 'woocommerce_after_shop_loop_item_title' , 'woocommerce_template_loop_price' , 10 );
      
      	add_action( 'woocommerce_single_product_summary' , 'woo_print_login_to_see' , 31 );
      	add_action( 'woocommerce_after_shop_loop_item' , 'woo_print_login_to_see' , 11 );
      	}
      }
      function woo_print_login_to_see()
      {
      	echo '<a href="' . get_permalink(wc_get_page_id( 'myaccount' )) . '" rel="nofollow">' .
      	__( 'Afficher les prix' , 'theme_name' ) . '</a>' ;
      }
      

      But I would rather include the original snippet into yours to understand how to add any other snippet that would work conditionally to hide the “add to cart” button.

      Here is my trial but lead to block my WP site :

      add_action( 'init' , 'woo_hide_price_and_button_not_logged_in' ); 
      function woo_hide_price_and_button_not_logged_in()
      {
      	if ( !is_user_logged_in() )
      	{
      
      
      function dac_add_cart_button ()
      {
          remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_add_to_cart', 10 );
      }
      add_action( 'after_setup_theme', 'dac_add_cart_button' );
      
      
      	remove_action( 'woocommerce_after_shop_loop_item' , 'woocommerce_template_loop_add_to_cart' , 10 );
      	remove_action( 'woocommerce_after_shop_loop_item_title' , 'woocommerce_template_loop_price' , 10 );
      
      	add_action( 'woocommerce_single_product_summary' , 'woo_print_login_to_see' , 31 );
      	add_action( 'woocommerce_after_shop_loop_item' , 'woo_print_login_to_see' , 11 );
      	}
      }
      function woo_print_login_to_see()
      {
      	echo '<a href="' . get_permalink(wc_get_page_id( 'myaccount' )) . '" rel="nofollow">' .
      	__( 'Afficher les prix' , 'theme_name' ) . '</a>' ;
      }
      

      It seem in deed that including a function into another didn’t work. If you could leed me on a good path it would be so great.

      Best regards and thanks for your great work.

      1. Hello there, thanks so much for your comment! Unfortunately this looks like custom troubleshooting work and I cannot help here via the blog comments. Thanks a lot for your understanding! ~R

  65. Still works, thanks a lot !

    1. Awesome 🙂

  66. Thank you very much Rodolfo, it works perfectly. Fantastic job!

  67. Nice Code Rodolfo,

    Quick question – While this hides the options on the product pages for non-logged in users does it also hide the prices from Google image search results that show products.

    Google still seems to be picking this up? Visible from a mobile search in Google images.

    Thanks

    1. Hey Gary, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

  68. Hi,

    Thank you for sharing this code! You’re the man!

    I have two quick questions?

    #1. Is there a way to have the variable options visible? Example: Size (dropdown)

    #2. Is there a way to display two different messages?

    Example:
    A custom message on the shop page?
    A custom message on the single product page?

    1. Hey Ryan, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

  69. Hi! After update to 3.3.4 something changed and none of these 3 variations seems to work. Can’t figure out what seems to be causing problem. As release notes dont show any changes related to these.

    1. Hey Michael, thanks so much for your comment! I just retested it on 3.3.4 and it works perfectly – sorry 🙂

  70. Hello, Can you give me the code in plugin form. Your code works but the requirement is to add a plugin of it

    1. I can’t, sorry Kalyani 🙂

  71. I use the divi theme and the woo layout injector plugin to customize the product pages. The code doesn’t seem to work on the custom pages I made with the plug in but it works on the normal woocommerce pages. Can you help me_

    1. Enrique, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

  72. Hello, this works great, however I have a “featured” products section on my home page that still displays the prices. Is there a snippet that could hide that as well? Thank you!

    1. It seems to be working perfect now! : )

  73. Hi Rodolfo

    What about hiding price and add to cart for a specific category (or categoris)?
    So that specific products can not be purchased before registration but other products can.

    Thanks.

  74. Hey

    It works for the simple product. But fro virtual product it shows add to cart button.

    1. Hey Harsh thanks for your comment! I just tried snippet #1 on WooCommerce 3.1.2. with a virtual product and it works. Please test with a different theme as that could be the reason why 🙂

  75. Hi ,

    Thank you for this. It has removed “Add to Cart” button and when hovered “login to see prices” comes up which is great but the price attached to the product does not get hidden ( when not hovered) . I want to hide price too. How do i do it?

    Many thanks,
    Kumar

    1. Kumar, thanks so much for your comment! Unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

  76. Nice code, thanks. Is there a chance to enable the price for the related products on the product detail site?

  77. Your code works great for the price! Unfortunately, I’m unable to get the “add to cart” to be removed. Is there a reason for this? I placed the snippet of code directly into my functions.php file.

  78. Hi..

    Tried all of them but not changed. Also disabled guest checkout.

    Using Woocommerce 3.0.5 with Php 5.6.25

    1. I see. Sorry, but this must be because of your custom theme/plugins. Check previous comments and you will possibly find a way to troubleshoot. Let me know 🙂

  79. Fantastic. Thank you. Snippet 3 did it for me!

    1. Thanks a million Rob!

      1. hello Rodolfo,
        I used snippet #2 and it worked. I don’t know why now in some product items appear the price. In the source code it is this statement:

        €0,00 / 1 Stück

        May be there was a change in relation with the recent Woocommerce updates ?!?
        Any idea ?
        Thanks a lot !
        cheers

        1. sorry, PHP:

          span class="wgm-info price-per-unit price-per-unit-loop ppu-variation-wrap"><span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">&euro;</span>0,00</span> / 1 Stück</span> 

          1. funny, just solved the prob:
            as “regular price” (0,00) there was “1” / per piece…….. there mustn’t be any number ! 😉

            1. Cool, glad I waited before replying 😀 Thank you Felix!

  80. Hi Rodolfo,

    Your code works great for the price! Unfortunately, I’m unable to get the “add to cart” to be removed. Is there a reason for this? I placed the snippet of code directly into my functions.php file.

    1. My apologies just saw the previous comment from Michael.

      1. Excellent 🙂 Keep me updated. If you find a custom code for your custom theme, I can add it here. Let me know

  81. Hi Rodolfo

    I added your functions and they worked for hiding prices but my add_to_cart buttons are still working. If unregistered customer pushes that buttons he can see his checkout process and all price in his basket 🙂
    Should I change any other thing ?
    Thanks for your support.

  82. Thank you Rodolfo for these snippets. I tried out #1 and #2 but i still see the button “add to cart”. Could you give me a tip?

    1. Hi Michael, thanks for your comment! It could be that your theme is overriding the default WooCommerce add to cart and therefore my functions won’t work and will need to be customized. Unfortunately this is custom work and I cannot provide a complementary solution here on the blog. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding! ~R

  83. Hello,
    which function .php should I add them for hiding price? In woocommerce pluging folder?

    thanks

    1. Hey Hasan, you can place this in your child theme’s functions.php file – if you need more guidance, please take a look at this video tutorial: https://businessbloomer.com/woocommerce-customization-hangout/. Hope this helps!

      1. thanks for reply, I try with child them didnot worked but when I changed default function .php is working properly 🙂 so what is the differences between both function page?

        by the way its not working with the items in best seller, top rated or Featured tab. Is there something that hiding price also from this area?

        //hasan

        1. Hey Hasan, thanks for your comment! If it works in the parent but not on the child theme, there is something wrong with your child theme – it should work there. In regard to the other issue, I can’t tell, as probably those are generated by your custom theme and my function would need to be edited to make it compatible to your specific situation 🙂 Thanks for your understanding!

  84. hello Rodolfo, Thanks for all your tips !
    After putting in any of the snippets I always get these error messages:

    Warning: Cannot modify header information – headers already sent by (output started at /www/htdocs/w01555d9/shop.dessousundmode.com/wp-includes/functions.php:1) in /www/htdocs/w01555d9/shop.xyz.com/wp-includes/pluggable.php on line 893

    Warning: Cannot modify header information – headers already sent by (output started at /www/htdocs/w01555d9/shop.dessousundmode.com/wp-includes/functions.php:1) in /www/htdocs/w01555d9/shop.xyz.com/wp-includes/pluggable.php on line 894

    I already looked for this error, seems like a syntax error………
    Can you give an advice? Thanks so much. Best regards Felix

    1. Hey Felix, thanks for your comment! If it was a syntax error it would show in the error log, while you’re getting the “headers already sent” error instead. I would try to re-write your whole functions.php from your FTP (delete the one you have, create a new one, paste the code), and see if it makes any difference. Let me know! 🙂

      1. thanks Rodolfo, I just did it, without succes……….. 🙁
        I must try another way…

        1. Strange 🙂 If you add a random snippet do you get the same error?

  85. hii,

    I want to disable some product price . This price show only when user login. and also add to cart disable button when user not logged such product.

    1. Hey Sandeep, thanks for your comment! You can probably make use of “conditional logic” and only trigger my snippet when a certain condition related to your “special products” is met. Try taking a look here: https://businessbloomer.com/woocommerce-conditional-logic-ultimate-php-guide/

  86. Hi.

    When I apply the code, snippet #1, by variable products it does now show the dropdown, hence not letting me see other variations of the products. Is there a way to fix this so I can see all variations of the products while having the price hidden?

    Thank you.

    1. Chaim, thanks for your comment! Yes, of course that is possible – unfortunately this is custom work and I cannot provide a complementary solution here on the blog. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding! ~R

  87. Thanks a lot, you snippet helped so much

    1. Brilliant, thanks so much for your feedback Lucas!

  88. Hi Rodolfo,
    Like your website and thanks for helping.
    I have used your snippet and adjusted to my theme and is working great but i’m not sure if i wrote it correctly can you please advice.

    add_action('after_setup_theme', 'bbloomer_hide_price_add_cart_not_logged_in');
     
    function bbloomer_hide_price_add_cart_not_logged_in()
    {
        if (!is_user_logged_in()) {
             add_action('woocommerce_single_product_summary', 'flatsome_catalog_mode_product', -99);
             add_action('woocommerce_single_product_lightbox_summary', 'flatsome_catalog_mode_lightbox', -99);
             add_filter('woocommerce_is_purchasable', 'flatsome_woocommerce_is_purchasable', 10, 2);
             remove_action('woocommerce_single_variation', 'woocommerce_single_variation_add_to_cart_button', 20);
             remove_action('flatsome_product_box_actions', 'flatsome_product_box_actions_add_to_cart', 1);
             add_filter( 'body_class', 'flatsome_body_classes_catalog_mode' );
        }else {
             remove_action('woocommerce_single_product_summary', 'flatsome_catalog_mode_product', -99);
             remove_action('woocommerce_single_product_lightbox_summary', 'flatsome_catalog_mode_lightbox', -99);
             remove_filter('woocommerce_is_purchasable', 'flatsome_woocommerce_is_purchasable', 10, 2);
             add_action('woocommerce_single_variation', 'woocommerce_single_variation_add_to_cart_button', 20);
             add_action('flatsome_product_box_actions', 'flatsome_product_box_actions_add_to_cart', 1);
             remove_filter( 'body_class', 'flatsome_body_classes_catalog_mode' );
        }
    }
    
    1. Hello Malchaz, thanks for your comment! Unfortunately I don’t use Flatsome theme so I have no idea – have you tried asking their support team?

  89. Hi Rodolfo!

    Thanks so much for this awesome snippet.
    We’re using it (V2.5.5) to hide prices and add to cart for logged out users.

    I have a quick question:
    Is it possible to ‘disable’ the function for a certain category please?
    Ie. Products of a certain category are excluded from this function, meaning they always show price and add to cart?

    We have products (in category with ID ’65’) that will be available to anyone, logged in or not – and we need to modify your function for this purpose.

    Any help would be hugely appreciated.
    And thanks again for this and all your useful info!

    1. Just wanted to clarify/summarize my previous question:

      1. Products in Category ‘specials’ must be available to add to cart and show pricing to everyone (logged in or logged out users)
      2. Everything else requires log in to add to cart or view prices.

      ————-
      So far we have successfully used your code to hide add to cart and pricing from anyone who is not logged in. We are working on excluding that one category from the function (or any other more elegant solution you may have!!)

      Thanks again, really appreciate it.

      1. Yes – that’s correct! You’re on the right track 🙂

        1. Thanks for the feedback Rodolfo,

          What we would need to know exactly is how to exclude that one category (say ID ’65’) from this function altogether please?

          So that one category would be excluded.

          1. Hey, thanks so much for your feedback! Yes, this is possible – but unfortunately this is custom work and I cannot provide this solution on the blog right now.

            If you would like to get a quote, feel free to go here.

            Thank you for your understanding!

            ~R

  90. Hi,

    The product image not showing for logged out users in woocommerce single product summary page. it is a variable product and have added the below code for logged out users. it is showing correctly for loggedin users.if it is a simple product it works fine.

    Regards
    Annie

    1. Annie, there is a CSS fix that has been around for a few months as many were getting the same problem – and it’s not related to this PHP snippet in particular. Try use:

      
      /* CSS to show product images @ single product page */
       
      .product.has-default-attributes.has-children > .images {
          opacity: 1 !important;
      }
      
      

      Let me know 🙂

  91. Hi – thanks for the snippet. My theme developers have tried to help me but we are now stuck. I have tried all versions of the snippet but it is hiding the variant selection drop downs. I have selected default variant and everything else works.

    1. Brett, thanks a lot for your feedback! I’m not entirely sure I understand your issue – this snippet hides the variation select box as long as I’m aware? Let me know! 🙂

      1. Hi Rodolfo,

        Thank you very much for sharing your code with in depth support for it.

        With variable product, I like to show visitors all the attributes but not the price except login users. ( by removing the 2nd remove_actions of your script)

        The ‘add to cart button’ was disabled when there is no options selected for the variable product or there is no stock for the product.

        I was wondering if there is a quick way to either move the “add to cart” button(keeping the options or attributes) or disable it (faking no-login-users with zero stock maybe?)

        Thanks in advance,

        Bob

        1. Hey Bob thanks for your comment! I’m not entirely sure your workaround would be the best way to proceed. What if you had a little PHP snippet that said “if product is variable, echo attributes as text”, without having to fake another solution?

      2. Ideally the non-logged in user should be able to view variants but not the prices. I need the variant drop downs to remain.

        1. In order to do that, you should look into the function “woocommerce_variable_add_to_cart()”. At some stage you will find a specific add_action for single variations. Therefore, try removing the add to cart by using:

          remove_action( 'woocommerce_single_variation', 'woocommerce_single_variation_add_to_cart_button', 20 );
          

          Let me know

  92. Sir
    u have sown us to hide price and add to cart for non logged users can it be done like until login it should say ” login to download ” once logged in
    in same place it should allow to download .

    1. and also pls tell where to insert the code u have showed here

      1. Thank you Anand. You can place this in your child theme’s functions.php file – if you need more guidance, please take a look at this video tutorial: “How to Customize WooCommerce with PHP Snippets (even if you don’t know PHP)“. Hope this helps!

    2. Anand, thank you for your comment. I’m afraid the “download” thing is not a WooCommerce default functionality, so this is a custom project that I can only help with if I have full access to your code and study your specifications. Sorry but I can’t help this time 🙂

  93. Is there a way to only show the prices and add-to-cart button for specific logged-in user roles?

    1. Hey John, thanks for your comment! Of course there is – take a look at what I’ve done here (different goal, yet you will understand the “user role” thing): https://businessbloomer.com/disable-payment-gateway-specific-user-role-woocommerce/

      Let me know 🙂

      1. Hello

        Your code works fine on the product page but on the home page add to cart button is still there and instead of printing a text its totally blank.

        1. Hey Junior, thanks for your message!

          I’m afraid my code only works on the shop, category and single product pages – it won’t work on the homepage I believe. You also have something custom there (the products look different from your shop page, are you using a shortcode or something like that?).

          I believe to fix this you will need custom coding, specific to your theme or custom homepage.

          Hope this helps!

          ~R

  94. Hey Rodolfo,
    I know this is not relevant to this particular article, but I was wondering if you have a visual hook guide for the checkout/ order received page?

    1. Hey Choco, yes, totally off topic 🙂 Nah, just kidding! Yes, you can find the checkout visual hook guide here. In relation to the thank you page, it has only 2 hooks:

      do_action( 'woocommerce_thankyou_' . $order->payment_method, $order->id )
      do_action( 'woocommerce_thankyou', $order->id )
      

      Hope this helps!

  95. Hello,

    How can I remove only add to cart for not registered customers ? They are allowed to see prices.

    Thanks for your help.

    Frank Blokzijl

    1. Hello Frank, and thanks for your comment! All you need is removing these 2 lines:

      remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
       remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
      

      Let me know if it works 🙂

  96. Hey Rodolfo Melogli

    Thanks for this amazing solution and your awesome “how to” videos! – Helped me ALOT!

    I have one question though..

    I can´t seem to change the “login to see price” text? – Maybe you can help me 🙂

    Thanks!

    1. seems like i figured it out myself! 😀

      1. Ahah Søren excellent! Thanks a lot for your comments 🙂

        1. Hmmm.. Seems i was wrong :/

          I can control text when im on the specific product page.

          But the button is still visible when your are on the page where you can see all products.. – I hope i make sense.

          Here is a link: https://www.vetcur.dk/produkter-2/

          1. And it removes the play button from my video i seems :/

          2. The function adds the same content to both the single product page and the “loop” page (where all products are). If you want a different message you need to split my snippet into 2:

            
            /**
             * @snippet       Hide Price & Add to Cart for Logged Out Users @ Single Page
             */
            
            add_action('init', 'bbloomer_hide_price_add_cart_not_logged_in_single');
            
            function bbloomer_hide_price_add_cart_not_logged_in_single() {	
            if ( !is_user_logged_in() ) {		
             remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
             remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
             add_action( 'woocommerce_single_product_summary', 'bbloomer_print_login_to_see_single', 31 );
            }
            }
            
            function bbloomer_print_login_to_see_single() {
            echo '<a href="' . get_permalink(woocommerce_get_page_id('myaccount')) . '">' . __('Login to see prices', 'theme_name') . '</a>';
            }
            
            

            And:

            
            /**
             * @snippet       Hide Price & Add to Cart for Logged Out Users @ Loop
             */
            
            add_action('init', 'bbloomer_hide_price_add_cart_not_logged_in_loop');
            
            function bbloomer_hide_price_add_cart_not_logged_in_loop() {	
            if ( !is_user_logged_in() ) {		
             remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
             remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );	
             add_action( 'woocommerce_after_shop_loop_item', 'bbloomer_print_login_to_see_loop', 11 );
            }
            }
            
            function bbloomer_print_login_to_see_loop() {
            echo '<a href="' . get_permalink(woocommerce_get_page_id('myaccount')) . '">' . __('Login to see prices', 'theme_name') . '</a>';
            }
            
            

            Let me know 🙂

  97. Hi Rodolfo, first tanks for all your work, since i started with WordPress your tutorials and codes where very helpful, i´ve the code and it works perfect.

    The only thing is when they preview the product o better say when they do a “quick view” in Flatsome the button for add to the cart shows and when they use it, they can see the price in the carshop.

    1. Francisco, thanks a lot for your message! I’m afraid my code works on a default installation of WooCommerce only. Your theme (Flatsome) is adding the “Quick View” functionality and therefore additional code will be necessary to remove the add to cart from there.

      You should search through the Flatsome theme PHP files for the function that creates the Quick View, then in some way remove it if users are not logged in.

      Unfortunately I don’t own the Flatsome theme and I don’t offer complementary snippet customisation. If you need technical help and you would like to get a quote for the fix, feel free to go here to get in touch.

      Thanks for your understanding!

      ~R

      1. Tnks for your answer, I decided yo disable the quick view! Tnks for your code – I will continue using.

        1. Awesome, thanks for letting me know Francisco 🙂

  98. Hi Rodolfo,

    I implemented your script and it hides the prices….However it also hides the QUANTITY.
    And I need that filed to enable a visitor to request a quote.

    Do you have a solution that ONLY hides the ADD to Cart-Button??|

    Thanks
    Bram

    1. Hey Bram, thanks for your comment!

      Yes, this snippet hides the add to cart and therefore the quantity as well – not sure having the quantity without the add to cart is necessary 🙂

      Do you have specific requirements? Let me know!

  99. Hi there. This sounds like the solution I have been looking for. Where do I place this code to get this to work? I’m new with this.

    Thanks,

    Holly

    1. Thank you Hollianne. You can place this in your child theme’s functions.php file – if you need more guidance, please take a look at this video tutorial: “How to Customize WooCommerce with PHP Snippets (even if you don’t know PHP)“. Hope this helps!

  100. Hi,

    Thanks for trying to help me in the Facebook group.
    Sad so say the help did not do much good for me.

    Will gladly send you login details + ftp login if you can assist me here.

    Best regards,
    Johan

    1. Thank you Johan – I’ll see what I can do 🙂 Please email me your details at info[AT]businessbloomer.com, thank you!

      1. Does the script handle attributes?

        1. You’re right, your WooCommerce CSS was also hiding images if the Add to Cart button was not present on variable products. I sent you the fix and also posted a brand new version of the snippet (#1) that should now work with all themes and all plugins.

          Glad I was able to help, and thanks for sharing your FTP details!

          Talk soon 🙂

  101. Hi,

    I tried your code on top of this page under: Hide add to cart & prices + show “Login to See Prices” instead

    I am using Generatepress as theme. I added the code at the end of functions.php but no result, the price does not disappear.

    Could you help me out?

    Michiel

    1. Hey Michiel, thanks for your comment! I strongly recommend not to edit your theme core files. You should build a child theme and place all your customization there. If you want to test the snippet you can alternatively use the free WP plugin called “Code Snippets”: download it, add a new snippet, place my PHP in there and see if it works. Let me know!

  102. Hi Rodolfo!

    First of all i would like to thank you for your help. I use your snippet and it works. But unfortunately the “add to cart” buttons are hidden for only 1 item and the rest of it still shows it. I use Flatsome theme and my website is drspiller.id. Could you check it up? I really count on you 😉
    Thanks.

    1. Hey Chico, thanks for your comment! Have you tried both snippets or only one? Someone had the same problem and switching to the other worked for them. Thanks 🙂

      1. Hello Rodolfo! The second one works better. Its hidding all the product prices. but the add to cart button are still showing up.. did i missing something? A very big thanks should i say 🙂

        1. Awesome 🙂 Re: add to cart, it could be that a plugin or theme is customizing that part already (remove_action( ‘woocommerce_after_shop_loop_item’, ‘woocommerce_template_loop_add_to_cart’, 10 );) and therefore you need to investigate further. Hope this helps!

          1. Hey rodolfo!Thanks a lot for your script.I am facing a tiny problem.Some of my variable products have different prices.When you go on the product page it says Login to see prices but if you select variables then is shows the different prices.Maybe i have to include an extra line to your code?

            1. Hey Mike, you’re welcome! So, the line:

              
              remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
              
              

              will remove the variation select box as well (on a default WooCommerce theme). Probably your theme or developer have customized something and my code is not removing what it should 🙂

              Please investigate and if you can’t manage to fix it feel free to get in touch.

              Cheers!

          2. Hey Rodolfo,I tried your other scripts and it worked better!!Thanks a lot!But another problem appeard.On the product page it wont show the product image.Is there anything i can do to fix that?Thanks again!

            1. That’s awesome Mike! Re: product image, I’m not sure. Can you give me a link so I can take a look?

          3. I send you a personal e-mail.Thanks a lot in advance Rodolfo!

            1. Thank you Mike, I’ve seen this problem before with variable products.

              Try adding this to your style.css:

              
              /* CSS to show product images @ single product page */
              
              .product.has-default-attributes.has-children > .images {
                  opacity: 1 !important;
              }
              
              
        2. Thanks a lot Rodolfo – it works!

          1. You’re welcome 🙂

            1. Hey again Rodolfo!
              I am facing again after months a tiny problem…Whenever i add a button to a page it wont show it unless i am logged in…I believe it has to do with this script cause in the visibility of the button i have it to say “Always visible”.Can you give me a hand?

              1. Mike, thanks for your comment. If you disable the script does your “button” show? It’s difficult to help you without a screenshot or URL – let me know 🙂

  103. Hi Rodolfo

    Interesting code, what about hide the price of selected products?

    1. Thanks for your comment Alain! In regard to your query, that’s an interesting one I must say – when you say “selected products” do you mean “products in the cart”?

  104. Hi

    I tried the code above (to hide prices unless logged in) in a PHP snippet, but it hides every page on the website when the function.php file is uploaded to the child theme folder.
    Is there something i’m missing or should i take it this code wont work with my theme?

    If its conflicting with the theme, do you know which files i should look at to try and edit?

    1. Hey Olly, thanks so much for your comment! This is weird, it works like a charm on WooCommerce 2.5.5 and Storefront theme. This should be placed in your child theme’s functions.php.

      Try switching theme and check if it works. If not, disable ALL plugins but WooCommerce and see if it works. In this case, you can then reactivate one plugin at a time to see which one is causing the conflict.

      Hope this helps 🙂

  105. Hi Rodolfo, thanks for your snippet. As some user, i have Avada theme and i can confirm your snippet don’t remove or hide “Add to cart” in single product page, and prices are showed in cart/checkout.

    If i’ll find some workaround will update you.

    Regards

    1. Thank you Riccardo for letting me know that 🙂 You can either Dropbox me the Avada files, or otherwise make a search for “woocommerce_single_product_summary” in the Avada files and let me know what results you get 🙂

  106. Hi Rodolfo,

    Sorry for wasting your wall, but I just fixed it myself.

    Very simple fix but not easy to figure out…

    Solution just choose a default variation on the product then everything loads perfect!

    Take care.

    – Mathias

    1. Awesome Mathias, glad to hear that 🙂 Keep in touch!

  107. Hi Rodolfo Melogli,

    First of all thanks for all the great code! I am a huge fan!

    I have just used your code for a page I am making for a friend. Everything in the code is working perfect except for one thing. Whenever I have a variable product the images do not show up… you can still click on them and then they show up just fine. The weird thing is that it does work fine on simple products.

    Variable product:
    https://www.furculture.com/shop/mink-stiletto/

    Simple product:
    https://www.furculture.com/shop/tray-in-seal-and-leather/

    I really hope you can help me out I have tried everything I can think of.

    Thanks

    – Mathias

    1. Mathias, thanks for your comment – much appreciated 🙂 Are you sure that my code causes this? If you disable my code does the image show? Thank you! ~R

      1. Thx for the code, but I have the same problem that Mathias Nielsen had. Images not showing. If I remove your code it is working. With the code, images only show on product page if clicked. Some how Mathias Nielsen has fix the problem, but didn’t show how. Can you help?

        1. Hey Mese, thanks for your comment! Are you having problems with variable products?

          1. Yes. Just variable products the images aren’t showing up.

            1. Take a look at his second reply – he explained there what the solution was for him. I will double check on my test website as well in the meanwhile! Thanks 🙂

          2. Oh, sorry I overlooked his reply. Thank you for the great and fast support! I don’t know why but it’s working with the default variation…

            1. Awesome 🙂 No problem at all, you’re welcome!

    2. Hi Mathias,
      Can you let me know how you have fixed this issue?. i am also having the same issue.
      Thanks & Regards,
      Annie

  108. Hi rodolfo, I use this code and it hide the pricing in products and shop, but add to cart still showing with the pricing.

    1. Thanks for your feedback Muhammad! Can you give me your website link and also send me a screenshot? Thank you!

  109. Any reason why the New code only displays the message for the first item like here: https://www.toritako.com/product-category/flags-banners/animals/birds-animals-amp-other-critters and the ‘old’ code displays it correctly beneath every product, but when you into the product it still shows my variations and prices.

    For now I have stuck with the New code and just dealing with the fact that it’s only shown on the first product.

    1. Thanks Chris for your feedback! It’s not the first time this happens to be honest. I will take a look at the code and revert if I can 🙂

    2. I just updated the snippet – this new version should work! 🙂

  110. I tried your updated code on the mystile theme, but nothing happened. All prices and ‘add to cart’ button still there.
    Has anybody done this with the mystile theme?

    cheers,
    C.

    1. Hey Christof, thanks for your feedback! I just tried the “alternative PHP snippet” (the second one on the blog page) on a Mystile test website and it works perfectly – try again 🙂

      1. Hello Rodolfo.

        I’m afraid I have to admit it’s a matter of RTFM… or something similar for your blogs.

        My mistake is that I added it to the functions.php of the theme. Since the theme probably already does some magic, the code didn’t work.
        That’s exactly why you repeat probably 10 times in your ‘How to Customize WooCommerce with PHP Snippets‘ video tutorial that one should NEVER EDIT YOUR THEME but always edit a child theme.

        So I created the child theme according to the simple wordpress.org instructions, then added your code to that functions.php… et voila!

        My appologies for not having figured this out immediately. But I thought to write down this info here again, just in case someone else needs it.

        Thanks for the help/code!

        Christof

        1. Awesome 🙂 Love your comment lol!!!

  111. This is great! Thanks!
    I was curious, my theme (MediaCenter) adds custom taxonomy for “brands”. Do you know how I could only hide prices for certain brands or at least where I should look to figure out how to filter them? Or, is there a way to easily filter using a custom field check box for each product and variation? Thanks for the help!

    theme: https://themeforest.net/item/mediacenter-electronics-store-woocommerce-theme/9177409

    1. Chase, thanks for your comment 🙂 In this case, you’ll need to ask your theme developers – you paid for it so they should be able to give you support! Otherwise, go look into the PHP files and see if you can identify anything that might help. Hope this is of any use 🙂 ~R

      1. Okay thanks, I will check.
        I guess I was hoping there was a generic way to check a custom taxonomy like your solution for checking categories:

        if (is_product_category( ‘shirts’ )) {
        // do something
        }

        1. Oh yes, there is definitely something like that! You can try using:

          
          /* change 'category_slug' with your Category Slug */
          /* do not edit 'product_cat' */
          
          if ( has_term( 'category_slug', 'product_cat' ) ) {
          // do something
          }
          
          
          1. That worked! Thanks, I did need a slight tweek:

            if ( has_term( ‘brand-slug’, ‘product_brand’ )

            I’m having another issues that is odd but I think this is a theme issue. You can see in the picture (https://oi66.tinypic.com/wbb712.jpg) that the prices are removed but the text that replaces the prices is only shown the first time. In the list view, it works right, only in the block view does this happen.

            Thanks again!

            1. Chase, thanks for your comment 🙂 In relation to the other issue, that’s pretty strange. Have you tried using the second snippet instead?

          2. yeah, i tried but no good.
            It’s very odd. The prices are cleared but after the first time the “new” price or text is displayed nothing is displayed after that only on the Grid view, the list view works just great. I’ve reached out to the theme creator to see if they know why. It’s just odd.

            1. Odd 🙂 A previous commenter found out this code only works in a child theme. I take you’re already using it?

          3. The Theme author is looking at it for me to see why it’s not working and to make the fix.
            Currently I am using a child theme though.

            1. Thank you Chase, keep us updated 🙂

            2. Chase, I just updated the snippet – this new version should work! 🙂

    1. You’re welcome Pablo! De nada 🙂

  112. Thanks for this post. The code has unfortunately stopped working! Do you have a replacement code?

    1. Tdang, thanks for your message! This snippet works on my test website so I find it unusual that it stopped working. Was it working before on your website? What did you do recently (updated theme / plugin)? Thank you

  113. I have tried this code. Its working But It seems like showing old content after logged in. For example, If unlogged user views a page which does not display the price details. Once he logged in then he click the same page again but It does not show price this time. When he refreshes the page, It shows the price. I have tried wc3 total cache plugin. Still struggling to address the issue. Please help

    1. Hello Ismail, thanks for this! I think this is an issue with your cache plugin, my snippet is not cache-friendly! If you remove W3TC, does the problem still occur?

  114. Hi and thanks for this code. I was wondering if there is a way to show only discounted prices to unlogged users?

    1. Reel, thanks for your feedback. I’m sure there is a way to do this but I’m afraid this is pretty custom and I’m very busy this week! Maybe I’ll create a post about this soon. R

      1. Hello Rodolfo,

        Thanks for the code.

        The snippet seems to hide my prices for both listed and single products, but the only issue I’m having is that my prices still show up in my cart (without being logged in). How can I remove his feature so people can only view the cart when logged in?

        I am using the theme ‘thefox’

        and here is my website link https://aceminiatures.co.uk/

        Thanks in advance
        Alex

        1. Hello Alex, thanks for your comment! To hide prices in the cart it’s a bit more complicated, as you will need to inspect in the WooCommerce PHP templates all the places where prices are generated. Question – if you hide the add to cart with my snippet – how can your users add to cart?

  115. First, thanks for this code. Looks awesome! I have 2 things:

    1. I am using the avada theme. On the page that displays all the products from that category, only the first product returns the link to login. Prices do get hidden though so thats good. Any idea why only one product would return that? All the single product pages are fine.

    2. Any way to only hide prices from one category? I have 2 divisions of my business and want to show pricing for one and hide prices for the other.

    Thanks!

    1. Josh thanks so much for your feedback. It’s possible that Avada theme is already overriding those filters and actions and therefore my snippet conflicts with your theme. I’m afraid I can’t provide the fix for you here as it is custom work.

      In relation to only hiding prices for one category, of course. You can use WooCommerce conditional rules to establish if you’re on a specific category page, and say e.g.

      if (is_product_category( ‘shirts’ )) {
      // do something
      }

      , where 12 is your category ID.

      Hope this helps!

      1. Thank you for the response. I am trying to make it work with your not logged in feature. I.e i want users NOT logged in to see category B’s prices and return the “login to see prices” for category A. Users logged in OR logged out to see category A and B. I used this statement

        // Hide prices

        add_action(‘after_setup_theme’,’activate_filter’) ;

        function activate_filter(){
        add_filter(‘woocommerce_get_price_html’, ‘show_price_logged’);
        }

        function show_price_logged($price){
        if(is_product_category( ‘B’ )){
        return $price;
        }
        elseif (is_user_logged_in() ) {

        return $price;

        }
        else
        {
        remove_action( ‘woocommerce_after_shop_loop_item’, ‘woocommerce_template_loop_add_to_cart’ );
        remove_action( ‘woocommerce_single_product_summary’, ‘woocommerce_template_single_price’, 10 );
        remove_action( ‘woocommerce_single_product_summary’, ‘woocommerce_template_single_add_to_cart’, 30 );
        remove_action( ‘woocommerce_after_shop_loop_item_title’, ‘woocommerce_template_loop_price’, 10 );
        return ‘‘ . __(‘Login to see prices’, ‘theme_name’) . ‘‘;
        }
        }

        If they are not logged in, it does not use the category conditional statement. It just hides all prices.

        Thank you for the help!!

        1. Sorry, one mistake in my last comment: I do not want users logged in or out to see prices from products in categories A and B. It should be:

          Logged in: See prices from products in category A and B

          Logged out: see prices from products in category B. Return “login to see prices” for products in category A.

          Thank you!

        2. There is something wrong in your if…else statements. In my opinion you should just use a simple if:

          if (!is_user_logged_in() && is_product_category( ‘A’ )) {
          // run function if user is not logged in and category is “A”
          }

          1. I tried that. I also tried replacing && with ||, but the is_user_logged_in() part seems to be the dominate function. Using this if statement, it will just hide all the prices if the user is logged out. It does not show prices for one of the categories when the user is logged out like I want.

          2. I was able to sort out my issue by using the has_term function. the is_product_category was not working. I am using this code which works for pages that only have 1 category on them. It works for pages with multiple categories but does not display the add to cart button for the product that you want to show prices and add to cart for when you are logged out.

            // Hide prices

            add_action( ‘after_setup_theme’,’activate_filter’) ;

            function activate_filter(){

            add_filter(‘woocommerce_get_price_html’, ‘show_price_logged’);

            }

            function show_price_logged($price){

            if (is_user_logged_in()) {

            return $price;

            }
            else{

            if( has_term( ‘moisturetint’, ‘product_cat’) ) {

            return $price;

            }
            else{
            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 );

            return ‘‘ . __(‘login to see prices’, ‘theme_name’) . ‘‘;

            remove_action( ‘woocommerce_single_product_summary’, ‘woocommerce_template_single_price’, 10 );

            remove_action( ‘woocommerce_after_shop_loop_item_title’, ‘woocommerce_template_loop_price’, 10 );

            }
            }

            }

            1. Awesome Josh, thanks for your feedback!

  116. Hallo…. I used storefront theme with germanized plugin and have the same problem as Micheal

    1. I add this code to disabled single price:

      remove_action( ‘woocommerce_after_shop_loop_item_title’, ‘woocommerce_gzd_template_single_price_unit’ );

      1. Thomas, thank you for this!

  117. Hi,

    This article is great and helped me understand a bit more what I’m trying to do, but I could just use some advice if possible.

    I’m using a third party theme (woopress) and my customer requires that the cart widget, add to cart and prices etc are hidden from non logged in users.

    Using your code I managed to hide prices, but the top cart widget in the header is still visible.

    I asked them for guidance and got nowhere, but I HAVE noticed that there’s a ‘catalog’ mode included in the theme, and I’ve found it in the theme functions file. Could you help me tweak it so that when the catalog mode is enabled, it only affects users that aren’t logged in?

    The code I’ve found is:

    // **********************************************************************//
    // ! Catalog Mode
    // **********************************************************************//

    function etheme_remove_loop_button(){
    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 );
    remove_action( 'woocommerce_simple_add_to_cart', 'woocommerce_simple_add_to_cart', 30 );
    remove_action( 'woocommerce_grouped_add_to_cart', 'woocommerce_grouped_add_to_cart', 30 );
    remove_action( 'woocommerce_variable_add_to_cart', 'woocommerce_variable_add_to_cart', 30 );
    remove_action( 'woocommerce_external_add_to_cart', 'woocommerce_external_add_to_cart', 30 );
    }

    add_action( 'after_setup_theme', 'et_catalog_setup', 18 );

    if(!function_exists('et_catalog_setup')) {
    function et_catalog_setup() {
    $just_catalog = etheme_get_option('just_catalog');

    if($just_catalog) {
    add_action('init','etheme_remove_loop_button');
    }

    Thanks in advance!

    1. Hey David, thanks for this. You could simply use “if(!is_user_logged_in() )” (which means “if the user is not logged in”) before the call:

      if($just_catalog && !is_user_logged_in()) {
      add_action('init','etheme_remove_loop_button');
      }
      

      Let me know 🙂

      1. Hi Rodolfo,

        It worked almost perfectly. When I enable catalog mode it now hides prices for logged out users, but shows them for logged in users.

        The only problem I’ve found is that enabling catalog mode hides the cart in the header of the site, so I just need to work out how to make sure that always shows for logged in users, and I think I’ve nailed it ! 🙂

        1. Great David! Thanks for your feedback 🙂

  118. Hi Rodolfo,

    I would like to add the “login/register to see prices” on all of product boxes, not just the first one on the page.

    can you help me add this?

    Michael

    1. Michael, thanks for your inquiry. To me, this looks like there is a conflict between your plugins or alternatively your theme has already customised the hooks and filters I used in my snippet. Maybe investigate a little further as this snippet works on almost all websites. Let me know!

      1. Not quite sure what you mean? the theme has customized your hooks and filters?

        1. Apologies Michael for not explaining well.

          In this snippet we use, for example, this:

          remove_action( ‘woocommerce_single_product_summary’, ‘woocommerce_template_single_price’, 10 )

          Now, this is giving for granted that your website has:

          add_action( ‘woocommerce_single_product_summary’, ‘woocommerce_template_single_price’, 10 )

          …which for standard themes will be there. However, if your theme developers have already worked on that particular hook, and say did something like:

          remove_action( ‘woocommerce_single_product_summary’, ‘woocommerce_template_single_price’, 10 )
          add_action( ‘woocommerce_single_product_summary’, ‘woocommerce_template_single_price’, 56 )

          …(note the 56 at the end of the add_action), once we apply the following, it won;t work:

          remove_action( ‘woocommerce_single_product_summary’, ‘woocommerce_template_single_price’, 10 )

          So, you have to make sure that your template is not overriding those hooks already.

          Hope this makes sense!

          R

          1. I had same issue using Avada theme. I solved this by rearranging the else statement as follows:

            else{
            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 );

            return ‘‘ . __(‘login to see prices’, ‘theme_name’) . ‘‘;

            remove_action( ‘woocommerce_single_product_summary’, ‘woocommerce_template_single_price’, 10 );

            remove_action( ‘woocommerce_after_shop_loop_item_title’, ‘woocommerce_template_loop_price’, 10 ); }

            *Notice the return is in the middle of the 4 remove_actions

  119. ‘.__(‘Login to see prices’, ‘theme_name’).’ i mean inside the a tag

    1. Awesome, fair play, thanks so much!

  120. this doesnt work with WPML.
    but this:

    return ‘‘.__(‘Login to see prices’, ‘theme_name’).’‘;

    Works perfect

  121. Hi how can i make the Login to see prices translatable.

    1. TB, thanks for your question! Just use “” (I also updated the code in the snippet, thanks for this!)

  122. We also want to remove price from logged out users, only logged in users may see the products prices. I used your given new code by just pasted it in themes function.php. It returned the page with your code written on it. I need your help in this regard. I am novice in woocommerce and PHP, Please provide me step by step guide.

    1. Hey Vaseem, thanks for your feedback! Did you paste the code at the bottom of your template’s functions.php file?

  123. the box of price

    1. I would like to hide the box surrounding the price, which is still visible
      thx 🙂

  124. yes I have this code:

    #product-box {
      display: none;
    }
    

    But it hides in all categories …
    This is possible only in certain category ?
    thx

    1. Yes Fred, how many categories do you need that for? Do you have the category IDs?

      1. I just need to hide in one category. No there is no ID but links …
        here’s the category where I want to hide the box: {…}

        thx in advance 🙂

        1. I don’t see the element you want to hide on that page. There are no prices?

  125. Hello, is it possible to hide the box of the price? (product box) in a category ?

    I find it but it hides the price and not the box …

    thanks 🙂

    1. Fred, yes this is possible. You will need to add some CSS to the PHP function to ask the system to display:none whatever element you’re trying to hide. Feel free to get in touch if you need a hand. R

  126. Dear Rodofil Melogi,

    Thanks for your code. But I need to disable prices everywhere including for all users. As our store will have bulk orders we want our users to have add to cart(for quotation) functionality but prices will be fixed after negotiations. Is there a way to remove prices from shop as well as cart and check out pages?

    Thanks in advance

    1. Arth, thanks for your feedback. I think you should take a look at this plugin, it hides all the prices everywhere and instead it puts a “quotation” button: WooCommerce Email Inquiry & Cart Options

  127. Hi how do I hide the “add to cart” button only for specific products? I wish to keep the price there but just hide the button only for individual products.

    Thank you

    1. Thanks for your enquiry! In order to apply any PHP to a specific product, simply use is_single(ID) where ID is the product ID. Hope this helps!

      1. Hi Rodolfo
        Thank you for the wonderful code :). If I wanted to show this only for a particular category what code would I enter? If you can give me the whole line of code and where to put it in your code that would be greatly appreciated.
        Thank you in advance.

        1. Hi Jacqui, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  128. Thanks so much for this!

    Need it for our wholesale store. Much appreciated.

    1. Thank you Josh! Your feedback is much appreciated as well 🙂

  129. can you give me the contact information I can send you to your FTP account edit

    1. Sure, just go here and use the contact form or my email address 🙂 Thank you

  130. I did like your guidance but faulty

    Warning: call_user_func_array() expects parameter 1 to be a valid callback, function ‘activate_filter’ not found or invalid function name in public_html/wp/wp-includes/plugin.php on line 496

    1. Sorry, I don’t really understand what you mean – can you explain again please? 🙂

  131. i also wish to do the same in my…I want to hide price and add to cart from general public and only for people with accounts. I tried the these and the price is gone, and it says (logged users only) but the add to cart button is still there. So if a non logged in users go to the site it says log in to view price but when they add to cart the price shows up. Please help me with this, been trying for about a week now, i haven’t been able to find a solution.

      1. found it in “content_single_product”

        * @hooked woocommerce_template_single_add_to_cart – 40

        1. Cool – then remove that action:

          remove_action( ‘woocommerce_single_product_summary’, ‘woocommerce_template_single_add_to_cart’, 40 );

          1. do i add that i function.php or bring content_single_product file into child theme?

            1. Sorry, it wasn’t clear 🙂

              Use this in your functions.php:

              // Hide prices
              
              add_action('after_setup_theme','activate_filter') ;
              
              function activate_filter(){
              add_filter('woocommerce_get_price_html', 'show_price_logged');
              }
              
              function show_price_logged($price){
              if(is_user_logged_in() ){
              return $price;
              }
              else
              {
              remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart' );
              remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
              remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 40 );
              remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
              return '<a href="' . get_permalink(woocommerce_get_page_id('myaccount')) . '">Login to See Prices</a>';
              }
              }
              
          2. ok i did it, but add to cart is still there =/

            1. Sorry to hear that 🙂 I will need to take a look at your template files in order to help. There must be something wrong with this as maybe that’s the wrong hook: remove_action( ‘woocommerce_single_product_summary‘, ‘woocommerce_template_single_add_to_cart’, 40 )

  132. I wish remove the prices but the functions adding to cart and finalize purchases continued to work, but without showing prices.
    This would serve to generate budgets. And this code doesnt work, the prices continue in the page. I’m paste the code in functions.php file of my template bin. Please, help me

    1. Vinicios, are you asking to remove prices only? Can you send a screenshot?

      1. Yes, i want to remove all prices of site or change the price by a text. Screenshot of my site: https://s14.postimg.org/fjfh7yczl/Untitled_2.jpg

        1. Check this blog out https://businessbloomer.com/woocommerce-add-prefix-suffix-product-prices/ and use the following modified function:

          
          // Remove price and add text
          
          add_filter('woocommerce_price_html', 'custom_text');
          add_filter('woocommerce_variable_price_html', 'custom_text');
          
          function custom_text() {
          $product = new WC_Product( get_the_ID() );
          $price = '<span class="price-text">TEXT HERE</span>';
          return $price;
          }
          
          
          1. Look the screenshot: https://s18.postimg.org/5ozodjhux/Untitled_3.jpg

            The code doesn’t work for all products and the text is dont showed correct.

            I’m try to use this too: https://businessbloomer.com/woocommerce-hide-column-cart-table/#comment-990 And when i put in the css file, it is stay with a syntax error.

            Pleas, help me

            1. I improved the code, take a look 🙂

  133. Thanks for this post. The code has unfortunately stopped working! Do you have a replacement code?

    Thank you in advance.

    1. Jessica, thank you for your comment! What error do you get on your website when you activate this code now? Or what did you do right before the code stopped working e.g. updated Woocommerce to what version? Thank you 🙂

      1. Thanks for the quick reply. This hides the prices to those not logged in but the add to cart feature is still not working. I read in another comment below that it is probably a theme issue? I am using the Travelify / Travelify Child theme and cannot seem to find where or what line “woocommerce_template_single_add_to_cart” is located?

        1. Yes, it could be that your theme has changed something in the hook, for example: remove_action( ‘woocommerce_single_product_summary’, ‘woocommerce_template_single_add_to_cart’, 50 ). please note the “50” at the end, instead of “30”. That priority could have been changed by your theme.

          Can you search for “woocommerce_template_single_add_to_cart” across your parent and child template files? (I use Notepad++ for this reason)

          1. Me again! I download Notepad++ but am not exactly sure how to use it to search for that?

            1. Download and extract your template files in your computer – then open Notepad++ and from the top menu select Search > Find in Files. Browse through your computer to find the template folder and that should do the trick!

          2. Thank you! I was able to search correctly but no results come up in travelify https://colorlib.com/wp/themes/travelify/ Do you have any other suggestions?

            1. Weird 🙂 If you send me your WordPress login/pwd and FTP hostname/username/pwd via email at infoATbusinessbloomer.com I can take a look!

            2. Jessica, I published a new version of the code – this should hide the add to cart button as well!

  134. Dear Rodolfo Melogli,

    i designed a eCommerce website as i share you the URL. But now i stuck with a problem. i.e. as per the company norms and conditions we can’t show the products price to guest user, means only register members can see the products price. to solve the problem i have come across with your solution. but after putting your code in function.php, i can’t find out anything please help me.

    Thanks.

    1. Prabir, thanks for your message! It seems you fixed this? If yes, what was the problem? Thanks!

      1. No, I just Paste the code but then what to do.

        1. Once you paste the code in your functions.php it should work automatically, you don’t need to take any additional step 🙂

          1. sory to say its not work. please please help me.

            1. Prabir, it worked for others so that’s weird. If you send me your WordPress login/pwd at infoATbusinessbloomer.com I can take a look!

          2. why its not remove the add to cart button for guest user. please help.

            1. Prabir, I can take a look at your code. Feel free to send me your WordPress login/password

            2. It works now, I just published a new version 🙂

  135. This code is not working for me… Hiding prices but not Add To Cart.

    1. Tayfun, thanks for your comment. It’s probably due to your theme, as they probably moved the “woocommerce_template_single_add_to_cart” already and assigned a different number (30 is the default). I recommend searching within your theme files for “woocommerce_template_single_add_to_cart” and you should be able to identify if they changed the hook. Hope this helps!

    2. Code should now work – check out the new version!

  136. Thank you this was very helpful. Exactly what I was looking for.

    1. Awesome Tim, thanks for your feedback!

  137. Thanks for this code, it is very helpful. However, it did not remove the Add to Cart button for me. Here is the page I am referring to:

    https://www.karen.kolbe-co.com/product-category/christmas/

    1. I don’t see any add to cart there 🙂

    2. It works now – check the new code 🙂

  138. Hi! I need to know how to get the icon to add to cart when not logged, please consider to make the same money can be added to the cart. I leave the site for your review. thank you very much

    https://www.voilab.cl/carro-de-compras

    1. Francisco, thanks for your comment. I don’t fully understand what you are trying to do. Are you asking to remove the “add to cart icon”?

  139. Thanks for useful snippets.

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

If you are writing code, please wrap it like so: [php]code_here[/php]. Failure to complying with this, as well as going off topic or not using the English language will result in comment disapproval. You should expect a reply in about 2 weeks - this is a popular blog but I need to get paid work done first. Please consider joining the Business Bloomer Club to get quick WooCommerce support. Thank you!

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