Okay
  Public Ticket #3455098
Sent out automatic reminders for all events
Closed

Comments

  •  1
    Panatda started the conversation

    Hi,

    Sorry for so many tickets, but is there a way to just enable auto reminders globally instead of having to go into each one and set reminds?

    Thanks,

    Panatda

  •  877
    Zhivko replied

    I recently wrote a hook for this:

    /**
     * Stachethemes Event Calendar 5.x mod
     * Automatically insert reminder for new attendees 2 days before event
     * @param (int) $result id of the newly created attendee
     * @return void
     * @since 5.0.7
     * 
     * @note: should be placed in the theme or child-theme (recommended) functions.php file
     */
    add_action('stec_after_attendee_create_item', function ($result) {
        
        if (false === is_numeric($result) || $result <= 0) {
            return;
        }     $event_id       = get_post_meta($result, 'event_id', true);
        $event_title    = get_post_meta($result, 'event_title', true);
        $attendee_id    = get_post_meta($result, 'attendee_id', true);
        $attendee_email = get_post_meta($result, 'attendee_email', true);
        $event_date     = get_post_meta($result, 'event_date', true); // Y-m-d\TH:i
        $attend_date    = get_post_meta($result, 'date', true); // Y-m-d\TH:i
        $remind_date    = get_post_meta($result, 'remind_date', true); // Y-m-d\TH:i
        $attend_state   = get_post_meta($result, 'state', true);     if (!$event_id || !$event_title || !$attendee_email || !$attend_date) {
            error_log('stec_after_attendee_create_item: missing data');
            return;
        }     if ($attend_state !== 'attending') {
            return;
        }     $event_timezone = \Stachethemes\Stec\Helpers::get_event_timezone($event_id);     $remind_date_object = new \DateTime($attend_date, new \DateTimeZone($event_timezone));
        $remind_date_object->sub(new \DateInterval('P2D')); // two days before the event
        $remind_date_string = $remind_date_object->format('Y-m-d\TH:i');     $title = implode('-', array(
            (0 !== $attendee_id ? $attendee_id : $attendee_email),
            $event_id,
            $event_date,
            $remind_date
        ));     require_once(ABSPATH . 'wp-admin/includes/post.php'); // requred for post_exists to work     $existing_post_id = post_exists($title, '', '', 'stec_remind');     if ($existing_post_id !== 0 && $existing_post_id !== (int) $data['id']) {
            // remind already exists
            return;
        }
        
        $remind_author = $attendee_id ? $attendee_id : 0;     $remind_post_data = array(
            'post_type'        => 'stec_remind',
            'post_status'      => 'publish',
            'comment_status'   => 'closed',
            'post_title'       => $title,
            'post_content'     => sprintf(
                esc_html__('You have an upcoming event tomorrow: %s', 'stec'),
                $event_title
            ), // you may want to edit this message
            'author'           => $remind_author,
            'meta_input'       => array(
                'author'            => $remind_author,
                'event_id'          => $event_id,
                'event_title'       => $event_title,
                'event_date'        => $attend_date,
                'user_id'           => $attendee_id,
                'remind_date'       => $remind_date_string,
                'email'             => $attendee_email,
                'tos'               => true,
                'read_permission'   => 'stec_private',
                'edit_permission'   => 'stec_private'
            )
        );     $result = wp_insert_post($remind_post_data);     if (is_wp_error($result)) {
            // log error
            error_log($result->get_error_message());
        }
    });

    Please this hook in your theme or child-theme functions.php file.


    Stachethemes Developer

  •  1
    Panatda replied

    Awesome. Thank you so much!