Sometimes you may need to add suffix or prefix to your Woocommerce product prices and if you would like to know how to accomplish that then see those two code snippets here below.
Pay attention that all the snippets shown below should be added to your child theme’s functions.php file or better yet, use a snippet manager like Code Snippets or WpCodeBox (my favorite). If you’re interested, then grab WPCodeBox with a nice 20% discount here (SAVE 20% Coupon WPSH20).
How to add a Suffix to WooCommerce Product Prices?
First lets add a suffix “per person” that is displayed both on archive and single product pages (see screenshot).
// Add a Suffix to WooCommerce Product Prices
add_filter( 'woocommerce_get_price_suffix', 'wpsh_woo_price_suffix', 99, 4 );
function wpsh_woo_price_suffix( $html, $product, $price, $qty ){
$html .= ' / per person';
return $html;
}
How to add a Prefix to WooCommerce Product Prices?
Next, let’s add a prefix “Per person:” that is displayed on your archive and single product pages (see screenshot).
// Add a prefix to WooCommerce product prices
add_filter( 'woocommerce_get_price_html', 'wpsh_woo_price_prefix', 99, 2 );
function wpsh_woo_price_prefix( $price, $product ){
$price = 'Per person: ' . $price;
return $price;
}