Display the value of a custom field in the email

WordPress Event Management, Calendars & Registration Forums General Question Display the value of a custom field in the email

This topic contains 4 replies, has 2 voices, and was last updated by  Nicolas Massart 10 years, 1 month ago.

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

    Hello,

    I created a custom field fot the events. I can display it on the event detail page with this code :

    <?php 
        $acompte = get_field('acompte');
        $formatted_price_acompte = eo_format_price( $acompte, true ); //Format price with currency
        echo $formatted_price_acompte;
    ?>
    

    Now I want to display it in the mail sent to my users after a booking. For this I’m editing this action :

    //Only send receipt on offline payment.
    add_action( 'eventorganiser_pre_gateway_booking_offline', 'email_booking_receipt' );
    //Uncomment the line below if necessary
    //add_action( 'eventorganiser_pre_gateway_booking_free', 'email_booking_receipt' );
    
    function email_booking_receipt( $booking_id ){
    
         //If you need it:
         $post_id = (int) eo_get_booking_meta( $booking_id, 'event_id' );
         $occurrence_id = (int) eo_get_booking_meta( $booking_id, 'occurrence_id' );
         $booking_amount = (int) eo_get_booking_meta( $booking_id, 'booking_amount' );
         $user_id = (int) eo_get_booking_meta( $booking_id, 'bookee' );
    
    
         //You may want to check that $booking_amount > 0 before proceeding
    
         /* Set the recipients email */
         $bookee_email = eo_get_booking_meta( $booking_id, 'bookee_email' );
    
         /* Set email template - optional */
         $template = eventorganiser_pro_get_option( 'email_template' );
    
         /* Set headers - optional */
         $from_name = get_bloginfo( 'name' );
         $from_email = get_option( 'admin_email' );
         $headers = "From: " . stripslashes_deep( html_entity_decode( $from_name, ENT_COMPAT, 'UTF-8' ) ) . "  <$from_email>\r\n";
         $headers .= "Reply-To: ". $from_email . "\r\n";
    
         /* Set message */
         $message = "

    My message

    "; $message = eventorganiser_email_template_tags( $message , $booking_id, $template );//Parses the email tags /* Set subject */ $subject = 'Votre inscription est en attente de validation'; /* Send message */ eventorganiser_mail( $bookee_email, $subject, $message, $headers, array(), $template ); }

    Could you please tell me how to achieve it ?

    Nicolas Massart
    #14917

    get_field() is a function in ACF (docs can be found here). The second argument allows you to pass the event (post) ID – $post_id in the above snippet.

    Stephen Harris
    #14918

    Thank you. I’m not an expert in php, I cannot get it working, could please tell me exactly what code to use and where in the snippet posted above ?

    Nicolas Massart
    #14930
    /* Set message */
    $acompte = get_field( 'acompte', $post_id );
    $formatted_price_acompte = eo_format_price( $acompte, true )
    $message = "This the custom field value: " . $formatted_price_acompte;
    
    Stephen Harris
    #14933

    Thx, works perfectly !

    Nicolas Massart
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.