How to hide prices from not logged-in users in your Magento 2?
Summer Nguyen | 08-28-2024
![How to hide prices from not logged-in users in your Magento 2?](https://cdn3.mageplaza.com/media/general/PavgLg0.png)
![How to hide prices from not logged-in users in your Magento 2?](https://cdn3.mageplaza.com/media/general/PavgLg0.png)
The Most Popular Extension Builder for Magento 2
With a big catalog of 224+ extensions for your online store
Price has always been transparent when it comes to online ecommerce. It is a significant factor that helps your stores reach customers the fastest and engage with them better in the buying process.
However, the power of ecommerce is changing how businesses work. Apart from retail stores, wholesale companies also want to reach out. Unlike retails, B2B buyers are smaller in number but significant in order value. These prospects need better commitment and care from the sales team. The function will encourage the customers to create an account at your site, which is often the beginning of long term partnerships.
If this is the function your business is looking for? Let’s tune in and learn about not logged in/login for price.
Why hide price if not logged-in needed?
Prevent price being exposed to opponents
It is challenging to avoid competition in many industries and fields. However, it can be minimized when you remove prices on your store sites and only allow the real clients who have the ability to login to view product price.
Thus, the rival distributors cannot investigate your price and lure your familiar customers at better pricing.
Increase customer retention
When customers are really interested in your products, they would like to see its price and willing to create a new account on the store sites. After all that time spending to form an account, they will try to see and learn more about the item.
Also, the convenience of having an account in your store sites will help shoppers have a better shopping experience such as purchasing history, check out information, etc.
Utilize customer data to market them
Furthermore, the required personal information will provide valuable customer data. This information will come in handy when you apply email marketing. You can send follow-up email, event emails, reminder email, rewards email, etc. In the content, you can add in materials emails with a welcome email or up-sell/cross-sell suggestions or sales promotions.
How to activate login for price
After all the benefits I have mentioned in the section above, you must be dying to know how you can set view price by login with Magento 2 Hide Price extension. There are two ways for you to place it in motion:
Setting via rules
Firstly, please access to Admin Panel, and moving on to Sales > Call For Price > Configuration, choose Manage Rules section. To create new rules with customer login requirements. There are three steps for you to add a new rule:
- Step 1: Fill in detail information in the General section
- Step 2: Configure the displayability with the rule on the frontend in the What to Show section
- Step 3: Create conditions to proceed with the rules on your products in the Where to Show section
The main point is where you can set customer login, right? This feature is located in the What to show section. You will understand clearer viewing the below picture:
In the Action field, there are four selections supported for you to select and continue to choose Login to See Price.
Setting via specific product
When you only want to apply this for certain products, it is possible to set directly in each product individually without having edit the complex rules.
Admins can log in to Catalog > Products > Add Product or Edit Product.
Subsequently, scrolling down and view Call for Price: The product will be applied based on the selected rule in this field: In the Call for price field, when you choose the select Inherit from Rule, the product will follow the conditions which have been set in the Rules section.
![Call for Price](https://cdn2.mageplaza.com/mp/assets/img/extensions-new/product-icon-png/ic_CALL FOR PRICE.png)
Unlock the potential of your product sales with our custom pricing options on Magento 2
Check it out!However, if you do not want to apply Inherit from Rule, it is possible for you to disable it and implement other rules with login for price. For example, you had set a rule to apply Popup a quote form with category Trousers. But for some products, you want customers to view the product price right after they login then you need to choose the name of the specific rule which contains login to view price.
Login for price on frontend
On the frontend, the price will show a button that redirects buyers to register/login to view the price instead of viewing price directly. The button flexibly shows on both the category page and product page. After the customer had log in, the price will be displayed usually on the store page.
Steps to hide price for not logged in customers in Magento 2
Step 1: Add di.xml in the following path: Vendor\Extension\etc
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
<preference for="Magento\Catalog\Pricing\Render\FinalPriceBox"
type="Vendor\Extension\Pricing\Render\FinalPriceBox" />
<preference for="Magento\ConfigurableProduct\Pricing\Render\FinalPriceBox"
type="Vendor\Extension\Pricing\Render\FinalPriceBox" />
</config>
Step 2: Create FinalPriceBox.php in the following path: Vendor\Extension\Pricing\Render
<?php
namespace Vendor\Extension\Pricing\Render;
use Magento\Framework\View\Element\Template\Context;
use Magento\Framework\Pricing\SaleableInterface;
use Magento\Framework\Pricing\Price\PriceInterface;
use Magento\Framework\Pricing\Render\RendererPool;
use Magento\Framework\App\Http\Context as HttpContext;
class FinalPriceBox extends \Magento\Catalog\Pricing\Render\FinalPriceBox
{
protected $httpContext;
public function __construct(
Context $context,
SaleableInterface $saleableItem,
PriceInterface $price,
RendererPool $rendererPool,
HttpContext $httpContext,
array $data = []
) {
$this->httpContext = $httpContext;
parent::__construct(
$context,
$saleableItem,
$price,
$rendererPool,
$data
);
}
protected function wrapResult($html)
{
$isLoggedIn = $this->httpContext->getValue(\Magento\Customer\Model\Context::CONTEXT_AUTH);
if ($isLoggedIn) {
return '<div class="price-box ' . $this->getData('css_classes') . '" ' .
'data-role="priceBox" ' .
'data-product-id="' . $this->getSaleableItem()->getId() . '"' .
'>' . $html . '</div>';
} else {
$wording = 'Please Login To See Price';
return '<div class="" ' .
'data-role="priceBox" ' .
'data-product-id="' . $this->getSaleableItem()->getId() . '"' .
'>' . $wording . '</div>';
}
}
}
Remember to run the command: php bin/magento s:d:c
and clear the cache before checking!
That’s all!
Final Words
In general, this is a unique feature for you to encourage customers to have a better commitment to the store and prevent your direct rival from accessing your item pricing.
Allow customer to see price by logging is a minor function which featured in Magento 2 Hide Price. It is a perfect solution for B2B to control price visibility. Customers will be motivated to contact stores and helps admins to conceal product prices information with ease.
![Hide Price](https://cdn2.mageplaza.com/mp/assets/img/extensions-new/product-icon-png/ic_HIDE PRICE.png)
Hide Price Extension for Magento 2
An efficient way to control price visibility by hiding prices for specific groups.
Check it out!