Send Notification on the Last Day of Every Month

Code

Filename: gpns-send-notification-on-the-last-day-of-every-month.php

<?php
/**
 * Gravity Perks // Notification Scheduler // Send Notification on the Last Day of Every Month
 * https://gravitywiz.com/documentation/gravity-forms-notification-scheduler/
 */
add_filter( 'gpns_schedule_timestamp', function ( $timestamp, $notification, $entry, $is_recurring, $current_time ) {

	// Update "123" to the form ID.
	$form_id = 123;

	// Update "1a23bc456def7" to the notification ID.
	$notification_id = '1a23bc456def7';

	// See https://www.php.net/manual/en/datetime.formats.php for supported date/time formats.
	if ( $is_recurring ) { // If the notification has just been triggered to send and the next recurring notification is being scheduled (if repeat is enabled)
		$desired_time = 'last day of next month 12:00 PM';
	} else {
		$desired_time = 'last day of this month 12:00 PM';
	}

	if ( (int) $entry['form_id'] !== (int) $form_id || $notification['id'] !== $notification_id ) {
		return $timestamp;
	}

	$local_timestamp = gmdate( 'Y-m-d H:i:s', strtotime( $desired_time ) );
	$utc_timestamp   = strtotime( get_gmt_from_date( $local_timestamp ) );

	return $utc_timestamp;
}, 10, 5 );

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.