WooCommerce Unit Price Snippet
Show a price per kilogram, litre or item next to the regular price, using the product's own weight field or a custom size field.
Your details
Your snippet
<?php
/**
* Show a price per unit next to the regular price.
*/
add_filter( 'woocommerce_get_price_suffix', 'ea_unit_price_suffix', 10, 4 );
function ea_unit_price_suffix( $html, $product, $price, $qty ) {
$size = (float) $product->get_weight();
if ( $size <= 0 ) {
return $html;
}
$unit = ea_weight_unit_label();
$unit_price = wc_price( round( (float) $price / $size, 2 ) );
return $html . sprintf( ' <span class="ea-unit-price">(%s / %s)</span>', $unit_price, esc_html( $unit ) );
}
function ea_weight_unit_label() {
$labels = array(
'kg' => __( 'kg', 'woocommerce' ),
'g' => __( 'g', 'woocommerce' ),
'lbs' => __( 'lbs', 'woocommerce' ),
'oz' => __( 'oz', 'woocommerce' ),
);
$unit = get_option( 'woocommerce_weight_unit', 'kg' );
return $labels[ $unit ] ?? $unit;
}
Uses your store's own weight unit (Settings → Products → Measurements), so the label follows whatever your products already use, kg, g, lbs or oz.
Products with no weight (or an empty custom field) are skipped on purpose, so it's safe to add this before every product has the field filled in.
Where the unit price appears
woocommerce_get_price_suffix is the filter WooCommerce already uses for the small text that follows a price, like a tax note ("incl. VAT"). This snippet adds a unit price there too, so it appears in the same place on the shop page, the single product page, and anywhere else the price prints.
Using the built-in Weight field means no extra setup for physical products you already ship. Weight-based unit pricing follows your store's weight unit (Settings → Products → Measurements → Weight unit: kg, g, lbs or oz).
Setting it up
- 01
Choose weight or a custom field
Weight needs nothing extra if you already fill in the Weight field under Product data → Shipping. A custom field works for units weight can't express, like sheets, metres or servings.
- 02
Fill in the field on your products
For weight, use the Shipping tab. For a custom field, add it under Product data → Advanced → Custom Fields, using the exact meta key you set here.
- 03
Paste the snippet and check a product page
Products with no weight (or an empty custom field) are left alone, so the snippet is safe to add store-wide before you've filled in every product.
Questions people ask
Why doesn't the unit price show on some products?
The snippet only adds it when the size value (weight or custom field) is greater than 0. Digital products, and any product with an empty Weight field, are skipped on purpose.
Can I show "per 100g" instead of "per kg"?
Yes, adjust the size you enter: if your Weight field is in kg and you want a per-100g figure, divide the weight by 10 before dividing the price, or switch your store's weight unit to grams under Settings → Products → Measurements.
Does this affect the price used at checkout?
No. This only adds text next to the displayed price; the actual price charged is untouched.
Is unit pricing legally required?
In some countries and categories (much of the EU, for food and household goods sold by weight or volume) it is. Check your local consumer protection rules; this tool builds the display, it doesn't confirm you're compliant.
Related tools
Last reviewed 30 September 2026.
Sources: WooCommerce source: abstract-wc-product.php · WooCommerce source: class-wc-settings-products.php (weight unit)
