Skip to content

Instantly share code, notes, and snippets.

@jameskoster
Created October 7, 2013 21:24
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jameskoster/6875202 to your computer and use it in GitHub Desktop.
Save jameskoster/6875202 to your computer and use it in GitHub Desktop.
WooCommerce - add text after price
add_filter( 'woocommerce_get_price_html', 'custom_price_message' );
function custom_price_message( $price ) {
$vat = ' (plus VAT)';
return $price . $vat;
}
@JapeNZ
Copy link

JapeNZ commented Mar 3, 2014

Hi there, I was wondering if it's possible to use this function on 'simple' products only?
I tried the following but frankly I have no idea what I'm doing:

global $post;
if( function_exists('get_product') ){
$product = get_product( $post->ID );
if( $product->is_type( 'simple' ) ){
add_filter( 'woocommerce_get_price_html', 'custom_price_message' );
function custom_price_message( $price ) {
$per = ' per month';
return $price . $per;
}
}
}

Any help would be most appreciated.
Cheers
JP

@arnaudds88
Copy link

Hi there, now how do you get this translatable?

add_filter( 'woocommerce_get_price_html', 'custom_price_message' );
function custom_price_message( $price ) {
$vat = ' (plus VAT)';
return $price . $vat;
}

@sjaaksola
Copy link

Reply to arnaudds88 message:

You can use echo function: __( 'Some text to translate and display.');
so your code would look like this:

add_filter( 'woocommerce_get_price_html', 'custom_price_message' );
function custom_price_message( $price ) {
  $vat = __('(plus VAT)');
  return $price . $vat;
}

and with css class and element, helps with styling:

add_filter( 'woocommerce_get_price_html', 'custom_price_message' );
function custom_price_message( $price ) {
  $new_price = $price . ' <span class="custom-price-prefix">' . __('(plus VAT)').'</span>';
  return $new_price;
}

Hope this helps! :)

@bilzone
Copy link

bilzone commented Sep 2, 2015

Hello,

And if i wan't to show some text after price only to product page how can i do ?

Thx in advance.

@jonnegarcia
Copy link

Thanks for this James, just want to ask, how can I do this in a specific product? Thanks in advance!

@riotinri
Copy link

you can go into the price template of single product and there you can add anything after the get_price_html(); and it will show after the price in single product only.

@alemarengo
Copy link

Hi!
Sorry for stupid question: how can I translate using WPML?

@violinman
Copy link

Looking to have a message appear only on products that have a price.
Could anyone help with the correct syntax
thanks very much

@tremblayly
Copy link

Hi
I have added the code snippet with CSS styles. However, since I already apply a font size change to the price using !important, when I try to apply a smaller font size to the text in brackets, it gets to use the price font size. How do I get this particular CSS font size to be applied only to the text.

Thanks
Lyse

@xbass540
Copy link

hi,
i followed the above code and managed to add some extra text after my price, but still over the "Add to Cart" button the text is not there, it appears only on the top of the product page under the title. Is there a way to change this as well?

Copy link

ghost commented Apr 20, 2018

Is it possible to load a widget after price, on the right?

@BatRTiago
Copy link

BatRTiago commented Feb 21, 2019

Hi,

For simple product, i try this code:

add_filter( 'woocommerce_get_price_html', 'custom_price_message' );
function custom_price_message( $price ) {
global $product;

// Limit to a specific product ID only (Set your product ID below )
if( $product->get_id() != 168 ) return;

// The content start below (with translatables texts)
?>
<?php
$vat = ' TTC/unitaire';
return $price . $vat;

}

@Gauravrana6999
Copy link

Hi,
can you please tell me how can I show the text ((*Incl. of all taxes) after a price on a single product page(wordpress) not is all product pages or in category pages? I just want to show this on a single product page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment