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.

Describe the result you need. AI will set up the tool and ask for any missing details.

Configure with AI

Enter to submit · Shift + Enter for a new line

Sent to AI. Leave out passwords and private customer data.

Your details

Your snippet

woocommerce-unit-price.php
<?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.

unit price = price ÷ size, where size is either the product's Weight field or a custom field you choose
Example: a jar priced at $9.00 with a Weight of 0.5 (in your store's weight unit) shows "$9.00 ($18.00 / kg)".

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

  1. 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.

  2. 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.

  3. 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.

Want this builtinto your store?

I'm Emmanuel, a Shopify and WooCommerce developer. If this tool pointed at something you'd rather have fixed for you (a faster store, cleaner product data, a migration, a custom feature), send me a note.

Emmanuel Asika

Emmanuel Asika

Shopify & WooCommerce developer, Dublin

I build and fix online stores: new builds, migrations, speed, SEO and the custom bits apps can't do.

hello@emmanuelasika.com