How to Hide Price in WooCommerce until Logged In?

There are numerous plugins for WooCommerce which can help you to Hide Price until the user is Logged In. But, if you do not wish to Hide Price via a plugin, you can follow the steps given below and make modifications in your WooCommerce theme.

Hide Price Until User Logged In

To Hide Price until the user is Logged In you need to add the following lines of code in your theme's functions.php file. Just append the following lines of code at the bottom of  functions.php

// Hide prices
add_action('after_setup_theme','magik_activate_filter') ; 

function magik_activate_filter()
{
   add_filter('woocommerce_get_price_html', 'magik_show_price_logged');
}

function magik_show_price_logged($price)
{
   if(is_user_logged_in() )
   {
      return $price;
   }
   else
  {
     remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
     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>';
  }
}


If you face any problems or need our professional services, please email us at [email protected]

Join our Newsletter

Never miss the latest offers, voucher codes and useful articles delivered weekly in your inbox.