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

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 ) {

    if ( ! $return_raw || ! is_admin() ) {

     $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/site-specific 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?

Do NOT follow this link or you will be banned from the site!