Support » Plugin: OneSignal - Web Push Notifications » Change the delivery time on the notification

  • secretuser

    (@secretuser)


    I want to change the delivery time on the notification:

    When I save a post on WordPress, the notification must be sent after exactly 10 minutes.

    Can you help me with this or build such a featured in the WordPress plugin?

Viewing 2 replies - 1 through 2 (of 2 total)
  • secretuser

    (@secretuser)

    Something like this:

    <?php
    add_filter(‘onesignal_send_notification’, ‘onesignal_send_notification_filter’, 10, 4);

    function onesignal_send_notification_filter($fields, $new_status, $old_status, $post)
    {
    // Schedule the notification to be sent after 10 minutes
    $date = new DateTime();
    $date->modify(“+10 minutes”);
    // echo $date->format(‘Y-m-d H:i:s’);
    $fields[‘send_after’] = $date;
    return $fields;
    }
    ?>

    secretuser

    (@secretuser)

    I write a code myself:
    I put this in functions.php and it worked!

    /////////////////////////////////
    // Add a delay of 10 minutes ////
    /////////////////////////////////

    add_filter(‘onesignal_send_notification’, ‘onesignal_send_notification_filter’, 10, 4);

    function onesignal_send_notification_filter($fields, $new_status, $old_status, $post)
    {
    $date = new DateTime();
    $date->modify(“+1 hours”);
    $date->modify(“+10 minutes”);
    $senddate = $date->format(‘M d Y H:i:s’).’ ‘ .’GMT+0100’;
    $fields[‘send_after’] = $senddate;
    return $fields;
    }
    ////////////////////////////

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.