14,000+ Active Installs
5,0 Star Review Average

WooCommerce Wholesale Prices: The Definitive Guide in 2020

August 15, 2020

This article is for any developer, WP agency or non-coder business owner that is using WooCommerce for their project, but needs a way to set up complex wholesale pricing (which WooCommerce doesn't provide by default).

We'll look at all relevant solutions: plugin solutions, as well as writing custom code and the right hooks to use for custom development. We'll also share several code snippets.

1. Set prices using a Premium Plugin

Let's start with the easiest way: using a premium plugin. B2BKing is a complete wholesale and B2B plugin with over 137+ features, including:

  • business registration
  • product bundles
  • built-in messaging system
  • wholesale pricing
  • discount, shipping, tax and order dynamic rules
  • tax exemptions
  • VAT number validation
  • purchase lists
  • business approval
  • product visibility control
  • invoice payment gateway
  • and many more.

B2BKing offers multiple methods to set wholesale prices, either directly, through CSV import or through discounts (product, category and bulk order discounts). The plugin is built for versatility and easy integration with any WooCommerce business, and you can even set discounts and prices for single specific users.

1.1 Set prices directly in the product page

The first step is going to the groups panel and setting up business groups.

B2B and B2C Groups in B2BKing

Go to "business groups" and click on "create new group". The following panel will open and you can also control which payment methods and shipping methods should be available to that group.

Once you have created a group, price fields for each group show up in the product page backend, for each product and for each variation. As you can see, it becomes incredibly simple to set prices for each group.

1.2 Import prices via CSV import/export tool

The process above can become cumbersome if you have a large number of products. That's why setting wholesale prices in B2BKing is done through meta-data. This means the plugin is compatible with any import/export tool such as WP All Import.

The plugin also has its own proprietary import/export tool that allows you export price lists, modify them directly in CSV/Excel and then import the file again to set prices.

Import / Export Tool for Wholesale Pricing via CSV

Recommended Import / Export Workflow

  • Step 1: Use the download button to get the current price list
  • Step 2: Modify the prices in the downloaded CSV file
  • Step 3: Upload the modified CSV with the import tool

1.3 Set a category or product discount for a user group

Besides setting product price directly for each product, you can also create dynamic rules for discounts, which can be global discounts, category discounts or product/variation discounts. The plugins introduces a powerful dynamic pricing component which also supports quantity/value conditions.

The example above is a configuration for a 50% discount, for the product Xiaomi Smart Vacuum for the user spencerllc.

Through the "show discount everywhere" setting, you can choose whether the discount should be visible in cart, or visible directly in the product page. Let's see what a wholesale discount visible in the product page looks like:

The name of the discount, in this case "B2B Discount" is also visible in the product page.

1.4 Set up bulk discounts based on quantity or value ordered

When creating discounts, you can also choose conditions based on the quantity/value of the product, category, or cart total that is being ordered.

For example:

A discount of 10% for all wholesale users, when they order at least $1000 worth of products.

1.5 Tiered Pricing Structures and Fixed Price Rules

You can take this a step further and create complex tiered pricing structures.

For example:

  • $1 per item for orders < 200 pieces
  • $0.95 per item for orders of 200-1000 pieces
  • $0.8 per item for orders > 1000 pieces

This can be set up by creating dynamic rules for either discount or fixed price with 2 or more conditions.

Configuration example for $0.95 price for 200-1000 pieces ordered:

Tiered Pricing Configuration

In the example above, price is set through a Fixed Price rule rather than a discount, which allows you to set a specific price for a product under certain conditions, for certain users or groups.

Update: B2BKing version 2.2.0 introduces Tiered Pricing in the Product Page + Pricing Table

Tiered pricing setup in the product page backend
Auto-generated Tiered Pricing Table in the Frontend

In conclusion:

The options of setting price in the product page, through discounts, bulk discounts, fixed price rules, for groups or for individual users, give you an unparalleled level of flexibility that allows you to take on even the most complex projects.

2. Set up wholesale pricing through custom coding

If you are a developer exploring a wholesale or b2b project, custom coding it could be the right solution for you. Let's explore the relevant items, hooks and filters that you need to use to modify WooCommerce pricing.

Generate regular price dynamically

The 2 hooks needed to set up regular price are

  • woocommerce_product_get_regular_price for simple products
  • woocommerce_product_variation_get_regular_price for variable products
add_filter( 'woocommerce_product_get_regular_price', 'b2bking_dynamic_rule_discount_regular_price', 9999, 2 );

add_filter( 'woocommerce_product_variation_get_regular_price', 'b2bking_dynamic_rule_discount_regular_price', 9999, 2 );

function b2bking_dynamic_rule_discount_regular_price( $regular_price, $product ){
	// run pricing logic
	return $regular_price;
}

Generate sale price dynamically

Sale price is more complex to generate dynamically, and the following filters are needed:

  • woocommerce_product_get_sale_price
  • woocommerce_product_variation_get_sale_price
  • woocommerce_variation_prices_price
  • woocommerce_variation_prices_sale_price

The price can be set up similarly to the regular price in the previous section

Clearing WooCommerce pricing cache

An important step when dealing with variable products in particular, is to clear the WooCommerce price cache, otherwise there will be a delay between setting the price and seeing the change displayed.

To clear the WooCommerce pricing cache use the following code:

add_filter( 'woocommerce_get_variation_prices_hash', 'b2bking_dynamic_rule_discount_sale_price_variation_hash', 99, 1);

function b2bking_dynamic_rule_discount_sale_price_variation_hash( $hash ) {
	if ($custom_pricing_logic){
           // clear cache
	   WC_Cache_Helper::get_transient_version( 'product', true );
	}

        $hash[] = get_current_user_id();
	return $hash;
}

Display formatted sale price

To display a sale price correctly, you should make use of the woocommerce_get_price_html filter and the wc_format_sale_price function.

add_filter( 'woocommerce_get_price_html', 'b2bking_dynamic_rule_discount_display_dynamic_price', 9999, 2 );

function b2bking_dynamic_rule_discount_display_dynamic_price( $price_html, $product ) {

    // run pricing logic

    $price_html = wc_format_sale_price( wc_get_price_to_display( $product, 
    array( 'price' => $product->get_regular_price() ) ), 
    wc_get_price_to_display( $product, array( 'price' => $product- 
    >get_sale_price() ) ) ) . $product->get_price_suffix();

    return $price_html;
}

Set sale price in cart

To modify the sale price in cart, the price must be set before totals are calculated, which is best done using the woocommerce_before_calculate_totals hook.

Update prices in the minicart as well

Prices in the minicart must also be updated separately, by using the woocommerce_cart_item_price filter

B2BKing is a product made with passion by SNP Digital, that we are constantly developing, supporting and improving.
Live Chat
linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram