Create Custom Menu in WordPress Dashboard
Complete tutorial on create custom menu in wordpress dashboard. Discover practical examples, implementation tips, and expert advice for WordPress and WooCo
Read More โTailoring prices for different customer segments like wholesalers, VIPs, or subscribers is a key strategy for B2B and membership-based stores. By registering custom user roles and adding specific meta boxes to the product editor, you can store unique price points for each role. Using the woocommerce_product_get_price filter, your store can automatically detect the logged-in user's role and serve the corresponding discounted price, creating a fully automated and private pricing structure without the need for complex plugins.
Want to offer different product pricing to business types like wholesalers or resellers? This guide shows how to set that up in WooCommerce using meta boxes and user roles.
Step 1: Add Custom User Roles
Create dedicated user roles using the following snippet or a plugin:
function define_custom_roles() {
add_role( 'wholesaler', 'Wholesaler', array( 'read' => true ) );
add_role( 'reseller', 'Reseller', array( 'read' => true ) );
add_role( 'business_customer', 'Business Customer', array( 'read' => true ) );
}
add_action( 'init', 'define_custom_roles' );
Step 2: Assign Roles to Customers
In the admin panel, assign roles like `wholesaler` to registered users as needed.
Step 3: Override Product Prices by Role
Use this filter to return a specific price if the logged-in user has a matching role:
function override_price_by_user_role( $price, $product ) {
$user = wp_get_current_user();
$roles = $user->roles;
foreach ( [ 'wholesaler', 'reseller', 'business_customer' ] as $role ) {
if ( in_array( $role, $roles ) ) {
$role_price = get_post_meta( $product->get_id(), '_' . $role . '_price', true );
if ( $role_price ) return $role_price;
}
}
return $price;
}
add_filter( 'woocommerce_product_get_price', 'override_price_by_user_role', 10, 2 );
Step 4: Add Custom Pricing Meta Boxes
Enable admin pricing input for different roles:
function register_role_price_boxes() {
$roles = ['wholesaler', 'reseller', 'business_customer'];
foreach ( $roles as $role ) {
add_meta_box( "{$role}_price_box", ucfirst($role) . ' Price', function($post) use ($role) {
$val = get_post_meta( $post->ID, "_{$role}_price", true );
echo '<label>Enter Price for ' . ucfirst($role) . ':</label> ';
echo '<input type="number" step="0.01" name="' . $role . '_price" value="' . esc_attr($val) . '" />';
}, 'product', 'normal' );
}
}
add_action( 'add_meta_boxes', 'register_role_price_boxes' );
function save_role_prices( $post_id ) {
foreach ( ['wholesaler_price', 'reseller_price', 'business_customer_price'] as $field ) {
if ( isset( $_POST[$field] ) ) {
update_post_meta( $post_id, '_' . $field, sanitize_text_field( $_POST[$field] ) );
}
}
}
add_action( 'save_post_product', 'save_role_prices' );
Once complete, your store will show different prices to different users based on their role — fully automated. 
Search our archives or reach out to our team for solutions and expert advice.