Login to show price woocommerce

Want to hide price of the product until user is logged in??

We will show you the easiest way. No prior coding knowledge required.

There are some plugins available for adding this functionality but we will avoid that.

You can either hide prices completely, or display alternate content in their place. For example, you could add a \’Login to view prices and place an order\’ message, linking to your login page.

For this tutorial, we’ll assume you already have the WooCommerce plugin set up on your WordPress website and some products added to your store.

This is how the normal shop page with products looks like.


Now navigate to Dashboard -> Appearance -> Theme Editor -> Functions.php

and paste the following code below.

add_action( \'init\', \'md_hide_price_add_cart\' );

function md_hide_price_add_cart() {
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\', \'md_view\', 31 );
add_action( \'woocommerce_after_shop_loop_item\', \'md_view\', 11 );

function md_view() {
echo \'\' . __(\'Login to see prices\', \'theme_name\') . \'\';

And voila here is the result.

** Don\’t forget to take backup before inserting the code in functions.php.


Leave a Comment

Your email address will not be published.