Okay
  Public Ticket #3408162
Displaying event data in notifications (&templates)
Closed

Comments

  •  1
    twothreenine started the conversation

    1. Is there a documentation of the codes that can be used to display event data in notifications, like {{event_start_date}} ? I'd like to include the event address for example (location name + street etc.)

    2. Can data like this be accessed in a template? I've tried out the Template Builder and would find it useful to make a field description object that includes codes like {{event_start_date}}, for example to display the event's address in a custom text field instead of the predefined table.

  •  877
    Zhivko replied

    Open your theme or child-theme functions.php file and add following PHP code:

    /**
     * Add special words to mail templates
     * 
     * @param array $filter array of special words
     * @param string $pre_content mail template content
     * @param int $event_id event id
     * @return array $filter array of special words
     * 
     * Adds following special words:
     * {{event_location_name}}
     * {{event_location_city}}
     * {{event_location_address}}
     * {{event_location_postal_code}}
     * {{event_location_country}}
     * 
     */
    add_filter('stec_mail_add_special_words', function ($filter, $pre_content, $event_id) {
        if (isset($filter['{{event_location_name}}'])) {
            return $filter;
        }
        $term = get_the_terms($event_id, 'stec_loc');
        if ($term && !is_wp_error($term)) {
            $term_id = $term[0]->term_id;
            $filter['{{event_location_name}}']          = $term[0]->name;
            $filter['{{event_location_city}}']          = get_term_meta($term_id, 'city', true);
            $filter['{{event_location_address}}']       = get_term_meta($term_id, 'address', true);
            $filter['{{event_location_postal_code}}']   = get_term_meta($term_id, 'postal_code', true);
            $filter['{{event_location_country}}']       = get_term_meta($term_id, 'country', true);
        }
        return $filter;
    }, 10, 3);
    

    This is a filter via which you can register your own special words.

    This one registers the following words:

      {{event_location_name}}
      {{event_location_city}}
      {{event_location_address}}
      {{event_location_postal_code}}
      {{event_location_country}}

    ---

    The builder does not have such placeholders. To be honest, I hadn't thought about it, so I will see if I can do something about this in the future.


    Stachethemes Developer