woocommerce_get_price_html
The woocommerce_get_price_html filter changes the formatted HTML returned for a product's displayed price. It receives the existing price markup and the product object, and the callback must return an HTML string. This is a display filter: it does not change the price used to calculate cart totals or payments.
| Type | Filter hook |
|---|---|
| Arguments | $price (HTML string), $product (WC_Product) |
| Return value | HTML string for the displayed price |
| Source | WooCommerce product price method |
Append a unit label
add_filter( 'woocommerce_get_price_html', function ( $price, $product ) {
if ( $product->is_type( 'simple' ) && '' !== $price ) {
$price .= ' <small class="unit-note">' .
esc_html( 'per item' ) . '</small>';
}
return $price;
}, 10, 2 );
This adds “per item” only to nonempty price markup for simple products. The existing HTML, including any sale-price formatting, remains intact; variable and other product types are left alone. Place the code in a site-specific plugin or child theme's functions.php and check both product cards and individual product pages.
Display behavior and limitations
WooCommerce builds the price markup before applying this filter, so $price may already contain a currency symbol, sale-price elements, or a range. The filter can run whenever code calls a product's get_price_html() method, not just on single-product pages. Do not use it to modify stored prices, taxes, or checkout amounts, and escape any dynamic text added to the returned HTML.
Classic templates use the filtered price markup. WooCommerce's Product Price block also calls get_price_html() during rendering, but interactive block updates can refresh prices separately. Verify the label in the particular layout rather than assuming every price display uses this filter.