Accessing custom fields in booking emails

WordPress Event Management, Calendars & Registration Forums General Question Accessing custom fields in booking emails

This topic contains 4 replies, has 2 voices, and was last updated by  Stephen Harris 6 years, 10 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #30040

    We have been using Event Organiser for a while to list our group’s workshops and recently we have gone with the Pro version for bookings. We have a number of custom fields for our events including a course number field. I’d like to be able to access the course number to put in the emails to admin and customer. Is there any way to do this other than to put the course number actually in the title of the event?

    Thanks

    http://www.ovwsg.com/?page_id=1067

    Judy Kavanagh
    #30050

    Hi Judy,

    The following code will create an email placeholder you can use:

    EO_Email_Template_Tag_Registry::register( 'myeventfield', function ( $tag, $atts, $context ){
        //$tag is 'myeventfield'
        //$atts is an array of attributes used with the tag
        //$context is an array indexed by 'booking_id', 'event_id', 'occurrence_id' etc. with
        //appropriate values for the context of the e-mail.
    
        $custom_field_key = $atts['key']; //or you can hard-code this
        $value = get_post_meta( $context['event_id'], $custom_field_key, true );
    
        return $value;
    }, 10, 3);
    

    And then you’d use it like this:

    %myeventfield key="my_custom_field_key"%
    
    Stephen Harris
    #30105

    Thanks

    I just don’t know where to put this: %myeventfield key=”my_custom_field_key”%

    Judy Kavanagh
    #30115

    OK, I got it to work, sort of. I put this in my site_utility.php file

    EO_Email_Template_Tag_Registry::register( ‘myeventfield’, function ( $tag, $atts, $context ){
    //$tag is ‘myeventfield’
    //$atts is an array of attributes used with the tag
    //$context is an array indexed by ‘booking_id’, ‘event_id’, ‘occurrence_id’ etc. with
    //appropriate values for the context of the e-mail.

    $custom_field_key = $atts['CourseNumber']; //or you can hard-code this
    $value = get_post_meta( $context['event_id'], $custom_field_key, true );
    
    return $value;
    

    }, 10, 3);

    It only works if I hard code ‘CourseNumber’. Then I can get the confirmation email to write the course number using
    %myeventfield key=”CourseNumber””%
    Yay!

    But if I have other custom fields I also want to access, how do I do that?

    And where do I find the code for the email that goes to the admin? I’d like to put the course number in that email as well.

    Thanks!

    Judy Kavanagh
    #30133

    Hi Judy,

    If you want to use as follows:

    %myeventfield key=”CourseNumber””%
    

    Then you should use

    $custom_field_key = $atts['key'];
    

    If you want to hardcode and want to create additional email tags, you just copy what you have, but with a different email tag name (i.e. change myeventfield to something else).

    As for the admin notification e-mail, please see this page. It details the filters for changing the admin notification message. Alternatively it provides a link to a plug-in which you can install which adds additional settings to Settings > Event Organiser > Bookings that allow you to change the admin e-mail notification.

    Stephen Harris
Viewing 5 posts - 1 through 5 (of 5 total)
To enable me to focus on Pro customers, only users who have a valid license for the Pro add-on may post new topics or replies in this forum. If you have a valid license, please log-in or register an account using the e-mail address you purchased the license with. If you don't you can purchase one here. Or there's always the WordPress repository forum.