Support

Home Forums Event Espresso Premium Mixing Free Events and Paid Events

Mixing Free Events and Paid Events

Posted: September 11, 2018 at 7:25 am


Phil Evans

September 11, 2018 at 7:25 am

Hi,

Some time ago, we used the following code

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

so that free events with a price of zero would display as “This is a free event/course”

However, we are now in the process of setting up paid courses and we’re testing using PayPal Express sandbox.

It looks like that code is displaying “This is a free event/course” whereever a balance of a paid for account is zero (i.e. payment has been made and approved).

So far, we’ve seen this on the thankyou page,

https://content.screencast.com/users/PhilEvans1/folders/Snagit/media/40d4709a-e355-4fd7-a953-8efc244ec69e/2018-09-11_14-25-26.png

As well as on the receipts, invoices and payment confirmation email
https://content.screencast.com/users/PhilEvans1/folders/Snagit/media/f82c201f-ad7f-4a33-9bc0-5c2ad4684c3f/2018-09-11_14-31-12.pnggrab

Payment Details:

Payment Status: Complete
Transaction ID: 15588
Total Cost: £75.00 (GBP)
Payment Amount: £75.00 (GBP)
Amount Due: This is a free event/course

As we’re offering both free and paid for courses, we want to be able to keep the “This is a free event/course” messages on free courses, but this shouldn’t show anywhere where a customer has paid.

How can we get around this?

Thanks

Phil


Josh

  • Support Staff

September 11, 2018 at 11:33 am

Hi Phil,

What you can do is make a slight adjustment to the code so it only alters the display if it’s a free event & it’s the page that shows the event information.

For example this:
if ( ! $return_raw ) {
can be changed to this:
if (! $return_raw && did_action('AHEE_event_details_before_post')) {


Phil Evans

September 11, 2018 at 12:07 pm

Hi Josh,

That tidies things up for the paid for courses, but now the free courses show £0.00 everywhere instead of “This is a free event/course”

so I’ve had t revert the code.

What I need to be able to do is display “This is a free event/course” if the course if free

and display the prices and remaining values where the course is a paid for course.

Regards

Phil


Josh

  • Support Staff

September 11, 2018 at 12:17 pm

Hi Phil,

It shouldn’t be an “everywhere” change as you suggest. The event page itself will still show “This is a free event/course”, within the ticket selector table.


Phil Evans

September 11, 2018 at 12:34 pm

This reply has been marked as private.


Josh

  • Support Staff

September 11, 2018 at 3:52 pm

Hi Phil,

There are some limits to what you can do with that filter, but a different approach would be to add a check for any front-end WordPress page. e.g. change the conditional to be:
if (! $return_raw && did_action('template_redirect')) {
Which will make it so the 0.00 is filtered to “This is a free event/course” if it’s a WordPress page on the front end of the website.


Phil Evans

September 12, 2018 at 12:46 am

Hi Josh,

Thanks. That’s almost perfect. Almost 🙂 is there any way we can either

a) disable invoices and receipts on free courses, where ticket price is zero or
b) force invoices and receipts to show “This is a free event/course” where price is zero

without upsetting the normal flow for paid for courses?

With thanks

Regards

Phil


Phil Evans

September 12, 2018 at 12:53 am

Hi Josh,

Sorry, just noticed the Event Payment Details email also still shows

Amount Due: This is a free event/course

Email

Is there a way to correct that so we show zero on paid for courses and “This is a free event/course” on free ones?

Thanks

Phil


Josh

  • Support Staff

September 12, 2018 at 4:19 pm

Are you sure that email was generated while the
&& did_action('template_redirect') code was in place? The template_redirect action shouldn’t have fired in the same request as the messages.

With regards to Receipts, Invoices & Free events, what you could do is remove the link to the Invoice from the Receipt (go to Event Espresso > Messages > Default Message Templates and end the Receipt template) You’ll remove the [INVOICE_RECEIPT_SWITCHER_BUTTON] shortcode from that template.

When someone registers for a free event they wouldn’t normally receive an invoice, unless they happened to click on the invoice button from the Receipt.


Phil Evans

September 13, 2018 at 2:30 am

Hi Josh,

I checked the code, flushed all caches and ran another test transaction and the Event Payment Details email still shows:

We’re just notifying you of a successful payment made for the following transaction and tickets:

Payment Details:

Payment Status: Complete
Transaction ID: 15601
Total Cost: £75.00 (GBP)
Payment Amount: £75.00 (GBP)
Amount Due: This is a free event/course
Event: Me In Mind Test

Ticket Name: Me In Mind
Price: £75.00 (GBP)
Quantity Purchased: 1

The code is as follows (I’ve commented out the two previous conditionals)

function convert_zero_to_free( $amount, $return_raw ) {
    // we don't want to mess with requests for unformatted values because those may get used in calculations
    // old statement if ( ! $return_raw ) {
    // 1st option if (! $return_raw && did_action('AHEE_event_details_before_post')){
    if (! $return_raw && did_action('template_redirect')) {
        $amount = $amount == 0 ?  __( 'This is a free event/course', 'event_espresso' ) : $amount;
    }
    return $amount;
}
add_filter( 'FHEE__EEH_Template__format_currency__amount', 'convert_zero_to_free', 10, 2 );

Regards

Phil


Josh

  • Support Staff

September 13, 2018 at 7:06 am

You could try changing the code to the following:

function convert_zero_to_free( $amount, $return_raw ) {
    if (! $return_raw ) {
        if (
            did_action('AHEE_event_details_before_post') === 1 
            || 
            did_action('AHEE__Single_Page_Checkout___initialize_reg_step__attendee_information') === 1
        ) {
        $amount = $amount == 0 ?  __( 'This is a free event/course', 'event_espresso' ) : $amount;
        }
    }
    return $amount;
}
add_filter( 'FHEE__EEH_Template__format_currency__amount', 'convert_zero_to_free', 10, 2 );

Which is a more precise conditional.


Phil Evans

September 13, 2018 at 8:29 am

Thanks Josh. That worked 🙂

With regards to invoices and receipts, is it possible to make the display and/or generation of those conditional on whether the course or event is free or not?

With thanks

Regards

Phil


Josh

  • Support Staff

September 13, 2018 at 8:34 am

Hi Phil,

What you can do is set up a custom receipt template that does not include a link to download an invoice, then assign that receipt template to all the free events. This is set within the event’s “Notifications” meta box.


Phil Evans

September 13, 2018 at 8:35 am

Thanks Josh. I’ll check that out this afternoon.

Thanks for all your help with this. Outstanding support as always.

Cheers

Phil

The support post ‘Mixing Free Events and Paid Events’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso