Add Custom Text to the WooCommerce Product Price

This snippet allows you to add any custom text to the price shown on the WooCommerce product and archive pages.

Perhaps you need to show some text after the price, for example: “$10 (all prices are in US Dollars).”

Or maybe you need to show some text before the price, for example “From $10”.

The snippets below allow you to do both. Just enter your before text on the $prepend line, and your after text on the $append line. If you only want to use one of them, just delete the text between the quotes.

Apply to all products

To apply the snippet to all WooCommerce products on your site, use the following snippet:

add_filter( 'woocommerce_get_price_html', 'snippetpress_wc_price_add_text' );

function snippetpress_wc_price_add_text( $price_html ){

    $append = 'Enter your before text here ';

    $prepend = ' Enter your after text here';

    $price_html = $append . $price_html . $prepend;
	
	return $price_html;
	
}

Apply to specific products

To apply the snippet to specific products on your site, use the following snippet. Enter the product IDs in the $products array on line 5:

add_filter( 'woocommerce_get_price_html', 'snippetpress_wc_price_add_text', 10, 2 );

function snippetpress_wc_price_add_text( $price_html, $product ){

    $products = array( 123, 456, 789 );

    if( in_array( $product->get_id(), $products ) ){

        $append = 'Enter your before text here ';

        $prepend = ' Enter your after text here';

        $price_html = $append . $price_html . $prepend;

    }
	
	return $price_html;
	
}

Apply to all products except specific products

This snippet will allow you to add text to the WooCommerce price on all products except for the ones you specify. Just add the products that you want to exclude from the snippet to the $products array on line 5:

add_filter( 'woocommerce_get_price_html', 'snippetpress_wc_price_add_text', 10, 2 );

function snippetpress_wc_price_add_text( $price_html, $product ){

    $products = array( 123, 456, 789 );

    if( !in_array( $product->get_id(), $products ) ){

        $append = 'Enter your before text here ';

        $prepend = ' Enter your after text here';

        $price_html = $append . $price_html . $prepend;

    }
	
	return $price_html;
	
}

Where to add the snippet?

Whichever snippet you choose to use, you should place it at the bottom of the functions.php file of your child theme. Make sure you know what you’re doing when editing this file. Alternatively, you can use a plugin such as Code Snippets to add the custom code to your WordPress site. If you need further guidance on how to add the code, check out our post on How to Add WordPress Snippets.