Skip to content

Unit price

Polish law requires online stores to show the unit price of a product - e.g. price per kilogram, liter or meter. Polski for WooCommerce adds this information automatically on the product page, in listings and in the cart.

The obligation to provide unit prices applies to products sold by weight, volume or length. In practice this includes:

  • food products (price per kg or liter)
  • cosmetics and cleaning products (price per 100 ml or liter)
  • construction materials (price per running meter or square meter)
  • bulk products (price per kg)

The unit price must be visible everywhere the product price is presented - on the product page, in search results, in price comparisons and in the cart.

Go to WooCommerce > Settings > Polski > Prices and enable the unit price module. After activation, a new section will appear in the product editor under the “General” tab.

FieldDescriptionExample
Base quantityProduct quantity in the package500
Base unitProduct unit of measurementg
Reference quantityReference quantity for the unit price1
Reference unitUnit for which the price is givenkg

For a product weighing 500 g with a price of 12.99 PLN, the plugin will automatically calculate the unit price as 25.98 PLN/kg.

The plugin supports the following units of measurement:

  • Weight: g, kg, mg
  • Volume: ml, l, cl
  • Length: mm, cm, m
  • Pieces: pcs (piece)

Conversion between units is automatic. If a product has weight in grams and the reference unit is kilogram, the plugin will calculate the value automatically.

For variable products, the unit price can be set at two levels:

  1. At the parent product level - value inherited by all variants
  2. At the variant level - overrides parent product settings

For variants with different weights (e.g. 250 g and 500 g packages), set the unit price separately for each variant. The plugin will automatically update the displayed price when the customer changes the variant (AJAX).

Use the shortcode [polski_unit_price] to display the unit price anywhere.

ParameterTypeDefaultDescription
product_idintcurrentProduct ID
beforestring""Text before the price
afterstring""Text after the price
wrapperstringspanWrapping HTML element

Basic usage on the product page:

[polski_unit_price]

With a custom product ID and text:

[polski_unit_price product_id="123" before="Price per kg: " after=" gross"]

In a PHP template:

echo do_shortcode('[polski_unit_price product_id="' . $product->get_id() . '"]');

This filter allows you to modify the unit price HTML before display.

apply_filters('polski/price/unit_price_html', string $html, float $unit_price, WC_Product $product, array $args): string
ParameterTypeDescription
$htmlstringGenerated unit price HTML
$unit_pricefloatCalculated unit price
$productWC_ProductWooCommerce product object
$argsarrayArray with keys: base_qty, base_unit, ref_qty, ref_unit
add_filter('polski/price/unit_price_html', function (string $html, float $unit_price, WC_Product $product, array $args): string {
$category_class = '';
if (has_term('napoje', 'product_cat', $product->get_id())) {
$category_class = ' polski-unit-price--beverage';
}
return sprintf(
'<span class="polski-unit-price%s">%s/%s</span>',
esc_attr($category_class),
wc_price($unit_price),
esc_html($args['ref_unit'])
);
}, 10, 4);

Example: hiding unit price for selected categories

Section titled “Example: hiding unit price for selected categories”
add_filter('polski/price/unit_price_html', function (string $html, float $unit_price, WC_Product $product): string {
if (has_term('uslugi', 'product_cat', $product->get_id())) {
return '';
}
return $html;
}, 10, 3);

Unit prices can be imported using the standard WooCommerce importer. Add the following columns to the CSV file:

CSV columnDescription
polski_unit_base_qtyBase quantity
polski_unit_base_unitBase unit
polski_unit_ref_qtyReference quantity
polski_unit_ref_unitReference unit

Example CSV row:

"Ground coffee 500g",29.99,500,g,1,kg

Check that:

  1. The unit price module is enabled in settings
  2. The product has the base quantity and unit fields filled in
  3. The theme supports the woocommerce_after_shop_loop_item_title hook (listing) and the woocommerce_single_product_summary hook (product page)

Make sure the base unit and reference unit belong to the same category (e.g. both weight or both volume). The plugin does not convert between categories - you cannot convert grams to liters.

This page is for informational purposes only and does not constitute legal advice. Consult a lawyer before implementation. Polski for WooCommerce is open source software (GPLv2) provided without warranty.