Support

Account

Home Forums General Issues Adding true/false ACF to The Events Calendar via functions.php

Solved

Adding true/false ACF to The Events Calendar via functions.php

  • Hi,

    I’m trying to create a ‘sold out’ function for events created and displayed via The Events Calendar plugin.

    I’ve created an ACF tickbox field (field name: sold_out) that if ticked will display ‘Sold Out’ on the events on the front end.

    Here’s where I’m up to, but currently this gives me ‘critical error on this website’ and breaks it –

    add_action(
    'tribe_template_after_include:events-pro/v2/photo/event/title',
    function () {
     if ( get_field( 'sold_out' ) ); 
     
     echo "SOLD OUT"; 
     
     endif;
     
     }
    );

    For context too I’ve already added in ‘Event Categories’ after the ‘Event Title’ using the same add_action.

    Quite new to coding so any help greatly appreciated.

    Cheers!
    Seamus

  • What is the error? Do you have debugging on so you can see the serrors?

  • Hi John,

    Thanks for helping.

    Debuggins is showing it’s the endif; that is throwing the error –

    PHP Parse error: syntax error, unexpected ‘endif’ (T_ENDIF)

  • With the syntax you are using the if statement should end with a colon instead of a semi-colon

    
    if ( get_field( 'sold_out' ) ) :
    
  • Ah I can’t believe that’s all it was. It’s working now though and appearing properly. Can’t thank you enough John!

  • I missed it the first time I looked at it as well, it is the kind of thing that the eye slips over and gets us all.

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.