When selling products to say wholesale and retail customers you’d probably want to offer different prices for the different customers. Best approach to accomplish this is by using user roles.

User roles allows you to group together regular customers and wholesale customers with native WordPress functionality. The user role can be changed from within the edit-user page.

Creating a New User Role

Before you can do this though you’ll have to create the ‘Wholesale’ user role first. The easiest way to do this is by running the following code snippet once.

add_action( 'admin_init', function() {
	add_role( 'wholesale', 'Wholesale customer', array( 'read' => true, ) );
} );

Add this to your themes functions.php file and refresh any admin page once to execute this. After that you can remove it. This snippet adds a new user role that is the same as the original ‘Customer’ user role, just with a different name so you can identify wholesale and retail customers.

Assigning the User Role

Within the edit-user page you can easily assign the new ‘Wholesale customer’ user role to the appropriate users.

This manual process works best if you have limited wholesale customers.

In case you have a lot of wholesale customers / they can register to your site on their own its a good idea to have a process in place that updates the user role accordingly. 

Setting Product Prices Based on User Role

This code snippet changes the price for the Wholesale customer for a specific product to $1. The product is identified by ID, but this could also be changed to something like SKU if wanted. 

It is possible to add additional price changes within the code snippet, simply duplicate the lines that check for the product ID / set the price and modify them accordingly for other products.

Creating a Custom Product Setting Field

If you want to setup wholesale prices for all your products, and you have a lot of them it would be nice to have a custom product setting field for that. This way the custom code snippet can be inserted once and prices can be managed from the WooCommerce User Interface. 

I wrote more about creating custom product settings in a separate blog post on my personal blog; Adding Custom WooCommerce Product Fields

Using a Advanced Pricing for WooCommerce

If you prefer to use a plugin to setup custom pricing per user role, using the Advanced Pricing for WooCommerce plugin is of course my recommendation. 

Within the plugin you’ll have options to create conditional pricing rules, including the conditions to setup pricing based on the user role. This also works perfectly with variable products.

When activating the plugin you’ll get a new ‘Pricing’ section with every product. In here you can setup pricing rules, and for this scenario using the ‘Role based price’ is fits perfectly.

After adding a rule you can configure for which role it applies and what the price change should be. In here’s its just a fixed price, but if wanted you can also say ‘-0.50’ for example to deduct cost of the original price.

It is possible to add additional pricing rules for other user roles or for bulk pricing for example.

About the author: Jeroen Sormani is actively building WordPress, WooCommerce and Easy Digital Downloads plugins. Slightly obsessed by writing high quality code.
Follow Jeroen on Twitter

Leave a Reply

Your email address will not be published. Required fields are marked *