Price is important in all e-commerce stores. Because price is the focus of research, product comparison and trend analysis. As a marketing strategy, you can hide product prices according to the specific user roles of the woocommerce store. But woocommerce basically has no option to hide the price. This post focuses on Pricing Based on user roles or insufficient roles (guest users). According to the user role, the store completely hides the product price. The main goal of this is to encourage users to register to view the price. To add this feature, stick to it. Best of all, it provides a step-by-step guide to hiding prices. But I need some technical knowledge.
Why hide prices before logging in? In many stores, you may not want everyone to browse online stores and view product catalogs. Here are some examples of prices that stores usually hide. A manufacturer that publishes details of wholesale store products that are not sold directly to the general public, but allows approved distributors to buy products. The first step to hide the prices of guest users in woocommerce member store is to hide the prices of all unlisted users. The steps to follow include:
Log in to the WordPress site and access the dashboard as an administrator. In the panel menu, click shape Menu > theme editor menu. If the theme editor page opens, find the theme feature file that hides the guest user price. Add the following code to the function: PHP file for storefront theme\/**
*Hide product prices according to user roles.
*\/
Function njengah_hide_price_guest ($price){
if ( ! is_user_logged_in() ) {
Return \
}
Return $price;
}
add_filter( ‘woocommerce_get_price_html’, ‘njengah_hide_prices_guests’ ); \/\/ The results of hiding product prices are as follows: The next step is to hide the shopping cart and check-out price and sum of guest users. functions. Add the following line to the PHP file: The steps to follow include:
Log in to the WordPress site and access the dashboard as an administrator. In the panel menu, click shape Menu > theme editor menu. If the theme editor page opens, browse the theme function file, hide the shopping basket, and pay the price and total number of guest users. Add the following code to the function: PHP file for storefront theme\/\/ Shopping Cart
add_filter( ‘woocommerce_cart_item_price’, ‘njengah_hide_prices_guests’ ); \/\/ Hide shopping cart item prices
add_filter( ‘woocommerce_cart_item_subtotal’, ‘njengah_hide_prices_guests’ ); \/\/ Total price of hidden shopping cart
To remove the price and total table headings, you can use CSS snipt to hide the headings. This PHP snipt adds CSS only when the user is not logged in\/**
*Use CSS to hide the price \/ summary table title.
*\/
Function njengah_hide_cart_checkout_price_headings_guest(){
if ( ! is_user_logged_in() ) {
?> 
.product-price, . Product somethod, \/ * shopping cart*\/
.woocommerce-mini-cart_
_Total, \/ * shopping cart parts*\/
.product-total, . cart-subtotal, . Order total \/ * checkout**
{display: none! Important;}
When the store has the role of wholesale user, it can also hide the prices of ordinary users or guest users. The following code snippet shows only the price of wholesale customers. functions. You must add it to your PHP file.
\/**
*Hide product prices according to user roles (or insufficient roles).
*\/
Function njengah_hide_price_user_role ($price){
$current_user = wp_get_current_user();
\
if ( ! array_intersect( $current_user->roles, $allowed_roles ) ) {
Return \
}
Return $price;
}
add_filter( ‘woocommerce_get_price_html’, ‘njengah_hide_prices_user_role’ ); \/\/ Hide product price
\/\/Shopping cart
add_filter( ‘woocommerce_cart_item_price’, ‘njengah_hide_prices_user_role’ ); \/\/ Hide shopping cart item prices
add_filter( ‘woocommerce_cart_item_subtotal’, ‘njengah_hide_prices_user_role’ ); \/\/ Total price of hidden shopping cart
\/\/Total settlement
add_filter( ‘woocommerce_cart_subtotal’, ‘njengah_hide_prices_user_role’ ); \/\/ Hidden shopping cart subtotal price
add_filter( ‘woocommerce_cart_total’, ‘njengah_hide_prices_user_role’ ); \/\/ Total price of hidden shopping cart
\/**
*Use CSS to hide the price \/ summary table title.
*\/
Function njengah_hide_cart_checkout_price_headings (){
$current_user = wp_get_current_user();
$allowed_roles = array (\
if ( ! array_intersect( $current_user->roles, $allowed_roles ) ) {
?> 
.product-price, . Product somethod, \/ * shopping cart*\/
. woocommerce Mini cart_total, \/ * shopping cart parts*\/
.product-total, . cart-subtotal, . Order total \/ * checkout**
{display: none! Important;}
<? php
}
}
add_action( 'wp_head', 'njengah_hide_cart_checkout_price_headings' ); To sum up, we shared a way to hide prices and show them to wholesalers. However, you can change the \
How to install a similar article step by step woocommerce storefront [complete guide] Woocommerce storefront method of setting home page woocommerce shopping cart and method page of putting settlement on one page Methods of deleting, renaming and adding screen sorting options methods of changing the order of foreground themes in product stores methods of hiding labels in store themes woocommerce