WooCommerce shows a bare price, but many WordPress shops sell per person, per night or per kilo, and the price needs that context. This snippet adds a prefix before and a suffix after WooCommerce product prices, on shop pages, single product pages and anywhere else WooCommerce prints a product price.
The example labels are “From:” in front and “incl. VAT” after. Most shops need only one of them; delete the other.
The snippet
<?php
/**
* Text before and after WooCommerce product prices.
* Keep only the add_filter() line and function you need.
*/
add_filter( 'woocommerce_get_price_html', 'dpc_price_prefix', 99, 2 );
add_filter( 'woocommerce_get_price_suffix', 'dpc_price_suffix', 99, 4 );
function dpc_price_prefix( $price_html, $product ) {
if ( '' === (string) $price_html || ( is_admin() && ! wp_doing_ajax() ) ) {
return $price_html;
}
return '<span class="dpc-price-prefix">' . esc_html__( 'From:', 'dpc' ) . '</span> ' . $price_html;
}
function dpc_price_suffix( $suffix_html, $product, $price = '', $qty = 1 ) {
if ( is_admin() && ! wp_doing_ajax() ) {
return $suffix_html;
}
return $suffix_html . ' <small class="dpc-price-suffix">' . esc_html__( 'incl. VAT', 'dpc' ) . '</small>';
}
How it works
woocommerce_get_price_htmlfilters the full price HTML, so the prefix lands in front of the amount, including sale prices and the price ranges of variable products.woocommerce_get_price_suffixfilters the suffix WooCommerce appends right after the amount (empty unless you set a tax display suffix), so the suffix stays inside the price markup.- Both labels pass through
esc_html__(), so they are escaped and translatable, and sit in adpc-price-prefixordpc-price-suffixelement you can style or hide with CSS. - A product without a price returns an empty string and the prefix is skipped, so you never get a lonely “From:”.
- In wp-admin (except AJAX) both functions step aside, so the Price column of the products list stays plain.
The older One-Click Import version used unprefixed wpsh_ function names, printed unescaped and untranslatable text, and added the labels in the admin products list too.
Add it with Scripts Organizer
In Scripts Organizer go to Code Blocks → Add New and give the block a name. Set Trigger location to Everywhere, tick PHP under Script location, paste the code into the PHP editor and publish. Leave Action/Hook empty. add_filter() only registers the callbacks; WooCommerce calls them when it renders a price, long after it has loaded. Conditions is not enough here, because WooCommerce also renders prices in AJAX responses (such as cart fragments and quick view plugins), and Conditions code only runs on normal front-end page loads.
The same code also works unchanged in a small plugin or an mu-plugin.
Customise it
- One category only: start each function with
if ( ! has_term( 'tours', 'product_cat', $product->get_id() ) ) { return $price_html; }(use$suffix_htmlin the suffix function). - Single product pages only: add
if ( ! is_product() ) { return $price_html; }to the prefix function. - Different wording: change the two strings; keep them short so prices don’t wrap on mobile.
If you only need text after the price and your shop has taxes enabled, WooCommerce has a built-in Price display suffix under WooCommerce → Settings → Tax. For a single label after the price, see also Add text after price.
Gotchas
- Classic templates and the Product Price block both use the product’s price HTML, so the labels show in both. Cart and checkout format line prices differently, so the labels don’t appear there, which is usually what you want.
- Priority
99runs after most themes and plugins. If another plugin rewrites the price HTML later, raise it. - Plugins that build their own price output instead of using the product’s price HTML won’t show the labels.
In the Scripts Organizer library Import it with one click from Scripts Organizer.