WooCommerce Price Hiding (For Not Registered Users)

With WooCommerce price hiding feature, you can hide the prices of all your products to users who visit your site and have not registered. You can also force users to login to see all prices and add products to the cart. It is possible to make this feature in WooCommerce catalog mode, but this time, […]

WooCommerce Price Hiding (For Not Registered Users)

With WooCommerce price hiding feature, you can hide the prices of all your products to users who visit your site and have not registered. You can also force users to login to see all prices and add products to the cart.

It is possible to make this feature in WooCommerce catalog mode, but this time, adding to the cart and prices will be hidden for registered users. With this method that I will tell you, you will be able to hide all prices and add to cart button for users who have not logged into your site. Moreover, you do not need to install a plugin for this process. Just add the php code I will share with you to any area of your theme’s functions.php file.

Important notice: In some cases (especially because of the theme) the code I will share with you below may not work properly. Please let me know if you encounter this type of problem.

WooCommerce Price Hiding Feature

So why should you hide a price? The answer to this question can be listed in a few variations. In particular, you may want to prevent competitors from seeing your prices, so you will not be affected by the variable prices in the free market. Or you may want to increase the number of registered members on your site. You can get great data and gain potential customers by forcing users to sign in and therefore to register. You can also periodically send e-mail and SMS marketing to these customers about your campaigns.

WooCommerce Price Hiding (For Not Registered Users)

PHP Code: Hide WooCommerce prices and add to cart button if the user is logged out or not logged in at all

You need to add the following code to your theme’s functions.php file. To do this, first login to your WordPress administration panel → then click view → open theme editing option and search functions.php in your theme files on the right-hand side and paste the code in a suitable place.

If “theme editing” does not appear in your administration panel, you can perform this operation via CPANEL or via FTP. The steps you need to take for this are as follows;

public_html → wp-content → themes → YOUR THEME→ functions.php

When you go to the directory above, let’s open the functions.php file with a text editor, paste the following code in a suitable place, then save and restore it to our host;

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 );
}
}
  
function bbloomer_print_login_to_see() {
echo '<a href="' . get_permalink(wc_get_page_id('myaccount')) . '">' . __('Sign in and see prices', 'theme_name') . '</a>';
}

In the code above, you can edit the ‘Sign in and see prices’ field on the last line. Clicking this will take the user to the login / registration page.

If you have followed the steps I explained above properly, this code will work without any problems. However, in some cases, setbacks may occur. In order to avoid every problem, make sure to take a backup before starting the process. Please send me any questions you have about the use of the code in the comments section.

Leave a Reply

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