To put a string before the price of WooCommerce product and cart pages, use the WooCommerce filters woocommerce_cart_item_price and woocommerce_get_price_html
Add the following code to your active theme functions.php file.
Make sure to change <span class=”price-prefix”>TEXT BEFORE THE PRICE</span> with your text or HTML code.
function wpxss_custom_html_addon_to_price( $price, $product ) {
// custom prefix html that you want to add before the price
$html_price_prefix = '<span class="price-prefix">TEXT BEFORE THE PRICE </span>';
if ( !empty( $price ) ) {
$price = $html_price_prefix . ' ' . $price;
return $price;
} else {
return $price;
}
}
add_filter( 'woocommerce_get_price_html', 'wpxss_custom_html_addon_to_price', 999, 2 );
add_filter( 'woocommerce_cart_item_price', 'wpxss_custom_html_addon_to_price', 999, 2 );
NEXT: How to Add text after the price in WooCommerce
Was this post helpful?
Let me know if you liked the post. That’s the only way I can improve. 🙂