How to set WooCommerce prices by user role
In this article, we look into how to set WooCommerce prices by user role. Our goal for today is to find automated ways to show different product prices for different users. In order to get this, we investigate some plugins and coding options. In addition, we dive into analyzing how using role based pricing with these different pricing strategies can affect your WooCommerce store performance.
Quite often we have different customer types. For example, we may sell at different wholesale and retail prices. Or maybe you have membership or discounts for different customer types as well. When it comes to the mechanics, using coupon codes is just too much work. One solution to this problem is to tailor the product price based on the WooCommerce roles. The concept of this solution is quite simple – use the WooCommerce customer role as a parameter to determine the product price.
WooCommerce, just like WordPress, is incredibly easy to extend. Since it has many different functions and hooks, we can create new functionality based on it. In addition, due to its ecosystem, it’s quite easy to find plugins to do what you want.
Therefore, today we look into different options for WooCommerce prices by specific user role. From the very basic definitions of user roles to plugin options and the actual implementation of multiple different WooCommerce product prices. In addition, we explore some options of how to analyze the effects of WooCommerce dynamic pricing.
Understanding WooCommerce prices by user role
By default, WordPress has 6 default roles, and WooCommerce has 2 extra roles. Thus, as soon as you activate your site with WooCommerce you have these options:
- Super Admin – For network installs, can manage all sites
- Administrator – Can manage everything in a site
- Editor – They Can manage all the content sections of a site (posts, media, pages, comments)
- Author – Can manage just their own posts, media and see comments
- Contributor – They can create posts and media, but they can only send them to review (no direct publishing)
- Subscriber – Nothing special, just a user role
- Customer – Registered using the WooCommerce forms
- Shop Manager – Similar to an editor, but just for WooCommerce-related content
These roles allow for basic user management. With them, you can give the right access to users who need them. Thus, for security reasons the different user roles are great. You won’t risk users see or edit content they shouldn’t.
In addition, you can use plugins to display content depending on the user role. Therefore, training material for your editors won’t be visible to regular users, for example.
But if you want to additional roles for customer segmentation, it’s possible to create new ones.
This allows not just customer segmentation, but customized content management as well. For instance, you can create a wholesale customer user role, and show some products just to these users or offer products at wholesale price. As for content, it’s possible to allow just customer from a membership role to access your VIP training.
There are many possibilities, and inside of this world of possibilities, there’s WooCommerce role based pricing.
WooCommerce dynamic pricing based on user role
One of the elements for a better customer relationship is a fair treatment. That’s why WooCommerce dynamic pricing is so important. With it, you can give different customers different prices which reflect the relationship they have with you. Let’s see some use cases for it.
It’s possible the use WooCommerce prices by user role for retail and wholesale pricing. The end result is simply different prices and different discount rules depending on the user type. This is set on their registration, or by an admin. Therefore, you set which users are from which type. Then using a plugin or some custom code different prices are applied.
The idea behind this is to create an offer that will only be available depending on the user type. For example, if you have an online store and you work with distributors you may want to give them a special wholesale price to buy a product in bulk. Therefore, you secure larger sales, and in exchange, you charge lower prices.
The end result is simply different prices and different discount rules depending on the user type.
There’s the possibility of memberships as well. Be it paid or free, a membership or member card is a way to get closer to your frequent buyers. Then, you can reward them with discounts, be it in specific product or site-wide. And the easiest way to implement this is by creating a user role for members, then use WooCommerce dynamic pricing.
Another interesting use for WooCommerce variable pricing is for customer contracts. Similar to wholesale customers, some customers have special contracts that grant them different pricing schemes. In addition, long-time customers or friends can have a different status in your business. This special status is translated into a different WooCommerce user role. This role can be used later for automatic discounts.
How to code WooCommerce role-based price
Now that we know what’s the importance of WooCommerce role pricing, it’s time to turn it into reality. If you are feeling adventurous, you can implement this change with some custom code. Luckily, WooCommerce has many hooks that we can use for this.
In short, this approach consists of 3 steps:
- Create your custom WordPress role (using a plugin or custom code) and assign it to your desired users. For that you can use a plugin like User Role editor.
- Create custom fields to your WooCommerce products, and use these fields to store the discounted price. You can easily add custom fields to your products by using a plugin like Advanced Custom Fields.
- Use WooCommerce hooks to apply this different price if the current user’s role is the one you set on step 1. This is the part that we are going to explain how to accomplish with custom code.
In our example, we will create a “wholesale_user” user role. Then we’ll add a special price for our products using a custom field called “wholesale_price”.
As WooCommerce has a lot of different product types, there are a lot of hooks that we need to use. Thus, we simply state all hooks for our products, then call an external function to actually do the WooCommerce price change.
Next, we get the current user role. Then we check if there is a custom price for that product. If there is we return the custom price. That’s it!
<?php // Hooks for simple, grouped, external and variation products add_filter('woocommerce_product_get_price', 'ui_custom_price_role', 99, 2 ); add_filter('woocommerce_product_get_regular_price', 'ui_custom_price_role', 99, 2 ); add_filter('woocommerce_product_variation_get_regular_price', 'ui_custom_price_role', 99, 2 ); add_filter('woocommerce_product_variation_get_price', 'ui_custom_price_role', 99, 2 ); function ui_custom_price_role( $price, $product ) { $price = ui_custom_price_handling( $price, $product ); return $price; } // Variable (price range) add_filter('woocommerce_variation_prices_price', 'ui_custom_variable_price', 99, 3 ); add_filter('woocommerce_variation_prices_regular_price', 'ui_custom_variable_price', 99, 3 ); function ui_custom_variable_price( $price, $variation, $product ) { $price = ui_custom_price_handling( $price, $product ); return $price; } //the magic happens here function ui_custom_price_handling($price, $product) { // Delete product cached price, remove comment if needed //wc_delete_product_transients($variation->get_id()); //get our current user $current_user = wp_get_current_user(); //check if the user role is the role we want if ( isset( $current_user->roles[0] ) && '' != $current_user->roles[0] && in_array( 'wholesale_user', $current_user->roles ) ) { //load the custom price for our product $custom_price = get_post_meta( $product->get_id(), 'wholesale_price', true ); //if there is a custom price, apply it if ( ! empty($custom_price) ) { $price = $custom_price; } } return $price; } ?>
But if you are looking for a quick implementation of custom prices per user role, then let’s use a plugin.
WooCommerce prices by user role plugins
WC Role Based Price
This WooCommerce plugin has a simple and translatable interface that can be used for custom WooCommerce prices by user rule. In addition, this plugin has a lot of functions that make it easy to expand and create new features.
Booster for WooCommerce
Booster is the go-to option for functions way beyond WooCommerce dynamic pricing. It includes currency conversion, global discounts, open pricing and much more.
Price based on User Role for WooCommerce
Simplicity is what defines this plugin. It’s extremely lightweight and does its purpose really well. If you want a quick option for WooCommerce prices by user role, this is certainly worth a shot. In addition to different prices, this plugin allows hiding products based on user roles.
How to analyze the effects of WooCommerce dynamic pricing
In addition to creating WooCommerce prices by user role, it’s a good idea to analyze its effects. For this reason, after the rollout, you can use a plugin such as Users Insights and inspect user behavior changes.
With Users Insights it’s possible to filter and segment users based on their WooCommerce activity. You just need to enable the WooCommerce module under Users Insights > Modules.
A quick check would be regarding repeat buyers by role. For this, you just need to filter users based on their role and then add the orders filter.
Another metric we want to improve is customer lifetime value. It is possible then to filter our most valuable customers for each user role or user role group. This is done using these filters:
But maybe not all of your users are aware of this change. You can let them know by email. For this, we just need to filter users who haven’t placed an order for the user roles we changed. Then you can export these users to MailChimp using a CSV file.
There are more complex filters, such as the “placed an order”. With it, you can combine multiple order metrics at once. Then you can add other filters to drill down your data and find the information you need. For example, if you want to filter all wholesale customers who placed a high-ticket order last month:
Conclusion
Today we looked into many aspects that of WooCommerce dynamic pricing. In addition to WooCommerce prices by user role, we saw how this can be used as a strategic tool. Thus, this strategy has marketing potential and is easy to implement. We went through the code implementation and plugin options to achieve it. After that, we looked into how to analyze results using Users Insights.
We hope you enjoyed and see you next time!