send Birthday Greeting with WP-SMS

[ad_1]

Hello,

Thank you for opening the topic this needs a custom cronjob to check the date from the database every day, but I’m thinking that might be a good feature to add this in WP SMS.

However, if you are familiar with WordPress Event/Cronjob, you can register an event to do that like this

function send_birthday_sms_greetings() {
    // Ensure this function only runs once a day
    if (get_transient('sent_birthday_sms_for_today')) {
        return;
    }

    $current_date = current_time('Y-m-d');

    // Query for users whose birthday is today
    $args = array(
        'meta_query' => array(
            array(
                'key' => 'birthdate', // Replace with actual meta key for birthdate
                'value' => $current_date,
                'compare' => 'LIKE'
            ),
        ),
    );
    $users = get_users($args);

    // Send SMS to each user
    foreach ($users as $user) {
        $message = "Happy Birthday! We hope you have a fantastic day!";
        $phone_number = get_user_meta($user->ID, 'phone_number', true); // Replace with actual meta key for phone number

        if ($phone_number) {
            wp_sms_send($phone_number, $message); // Replace with actual function to send SMS
        }
    }

    // Set a transient to prevent the function from running again today
    set_transient('sent_birthday_sms_for_today', true, DAY_IN_SECONDS);
}

// Hook the function into WP-Cron
if (!wp_next_scheduled('send_birthday_sms_greetings_hook')) {
    wp_schedule_event(strtotime('06:00:00'), 'daily', 'send_birthday_sms_greetings_hook');
}

add_action('send_birthday_sms_greetings_hook', 'send_birthday_sms_greetings');

I haven’t tested it yet but need to be test.

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer