Ubercart - Modify Product Price Display

Kevin's picture

[b]Q:[/b] I want to add some text like 'Incl. VAT' to the end of my [url=http://www.google.ie/url?sa=t&source=web&cd=1&ved=0CCsQFjAA&url=http%3A%... product price when it's displayed, how do I do this?
[b]A:[/b] In ubercart this is harder than you might expect, you have to add an ubercart 'price handler' that will change how the price is displayed, this is done in a custom module.

Some things in ubercart can be quite hard to achieve, one such is modifying the product price display. To modify how a price is displayed you have to define a 'price handler', to view and enable existing price handlers go to: admin/store/settings/price-handlers, there probably aren't any defined on your installation yet....

The problem is that this screen doesn't allow you to define new handlers, to do that you have to write your own module (erk!) ....

As an example let's say that we want to append the text 'Incl. VAT' to the end of the price. First you need to create an module, if you are not familiar with this have a look at the [url=http://drupal.org/project/module_builder]Module Builder[/url] module which should help you with setting up an empty module.

Once you have a module (nicely skipped over the difficult bit!), you need to define a price handler. You do this by implementing hook_uc_price_handler() like this:


function pride_mods_uc_price_handler() {
return array(
'alter' => array(
'title' => t('Pride Design VAT suffix'),
'description' => t("Adds 'Incl. VAT' after price."),
'callback' => 'price_handler',
)
);
}

This is the function that I added to my module (called pride_mods), it defines a price handler called 'Pride Design VAT suffix', and indicates that the actual handler function to be called to alter the price is price_handler().

Remember to replace the pride_mods bit in the function name with your module name or ubercart won;t pick up on it.

Next we just have to define the price_handler() function:


function price_handler(&$price_info, &$context, &$options) {
$options['suffixes'][] = " Incl. VAT";
}

There are loads of things you can do to the price, in this case we are just appending some text by adding a suffix, we append it to the suffixex array on th options argument. There are loads more things you can do, take a look at the documentation for more details (if you can find them!)

Once you have the code in and your module enabled, and assuming your site is still working, head over to the ubercart price handler settings:

admin/store/settings/price-handlers

You should see your handler listed. Once you enable it your prices should be modified.

It's all a bit involved, but works well when you have got it all setup.

Drop us a comment if you would like more details or if you would like me to post an example module, I'm just too knackered to write one up now but I will if anybody's interested!

Share this post: 

Recent Work

Some of Ireland's biggest brands use Pride Design to Design, Build, Manage, Market and Maintain their websites.

Website design for St.Patricks Credit Union in Dublin, Including Loan Calculators.

Website design and development for a step by step wedding and other stationary ordering website f

New website designed and developed for Cork's newest café, which is based in Merchants Quay in Co

New Website design for Pain Relief clinic based in Cork City.

Website for a busy Dublin city centre pub.

We redrafted the Ballymaloe house website to modernise the look and feel of the site and to also

We revamped the website for the Ballymaloe Cookery School.

We revamped the Cully & Sully website onto Drupal.

Rachel Allen was brought up in Dublin and left home at eighteen to study at the world-famous Ball

Clóna Dairy Products are a Dairy Company based in Clonakilty, Co. Cork, since 1919.

Project Arts Centre is Ireland’s leading centre for the presentation and development of c