How to Show a Ticket with a Price of Zero as Free

In this post we’ll learn how to show tickets that have a cost of zero as free. Lets begin by taking a look at the screenshot below:

ticket-selector-zero-pricing

We can see that we have a free ticket that has a pricing of zero (shown as 0.00). Do you host events that have free tickets? Wouldn’t it be great to be able to show the price as “free” instead of “0.00.”

You can enable this on your own site with a filter.

function convert_zero_to_free( $amount, $return_raw ) {
    // we don't want to mess with requests for unformated values because those may get used in calculations
    if ( ! $return_raw ) {
        $amount = $amount == 0 ?  __( 'free', 'event_espresso' ) : $amount;
    }
    return $amount;
}
add_filter( 'FHEE__EEH_Template__format_currency__amount', 'convert_zero_to_free', 10, 2 );

There are a couple ways to add the filter above to your site. The first is to add the code to your theme’s functions.php file. However, this edit may be lost if you update your theme and it removes and replaces the functions.php file. A safer method is to create a custom plugin.

Once this filter is in place, go to any events on your site that has a free ticket and you’ll see that the pricing has been transformed from 0.00 to free:

ticket-selector-free-pricing


Need more help?

  • Browse or search for more information on this topic in our support forums. Customers with an active support license can open a support topic and get help from Event Espresso staff.
  • Have an emergency? Purchase a support token and get expedited one-on-one help!
  • Go back to documentation for Event Espresso
Event Espresso - Staging Server