Skip Sundays for Drip Campaigns

This snippet will automatically adjust a notification’s “Delay” schedule to ensure that it is not sent on a Sunday. All subsequent notifications with have their delay automatically adjusted to ensure that they arrive in the correct order. This requires that all notifications be created in the exact order that they should be received.

Code

Filename: gpns-skip-sundays.php

<?php
/**
 * Gravity Perks // Notification Scheduler // Skip Sundays for Drip Campaigns
 * https://gravitywiz.com/documentation/gravity-forms-notification-scheduler/
 *
 * This snippet will automatically adjust a notification's "Delay" schedule to ensure that it is not sent on a Sunday.
 * All subsequent notifications with have their delay automatically adjusted to ensure that they arrive in the correct
 * order. This requires that all notifications be created in the exact order that they should be received.
 */
add_filter( 'gpns_schedule_timestamp_123', function( $schedule_datetime ) {
	static $buffer;

	if ( $buffer === null ) {
		$buffer = 0;
	}

	$date = DateTime::createFromFormat( 'U', $schedule_datetime );

	if ( $buffer > 0 ) {
		$date->add( new DateInterval( "P{$buffer}D" ) );
	}

	if ( $date->format( 'l' ) === 'Sunday' ) {
		$date->add( new DateInterval( 'P1D' ) );
		$buffer++;
	}

	if ( $buffer <= 0 ) {
		return $schedule_datetime;
	}

	return $date->format( 'U' );
}, 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.