Manipulate User Subscription Start Date [RESOLVED]

I am creating a drip campaign on MailChimp for an online course. I am able to trigger the drip campaign on a user-selected start date. However, MailChimp will not let me edit the TIME. So if someone happens to have registered at 1 p.m., MailChimp will trigger the campaign at 1 p.m. on the specified start date.

Since they’re unable to provide a fix, I thought maybe I could manipulate the data on form submission to set their registration time for midnight, no matter when it’s submitted. I tried this (borrowed from here) but was unsuccessful.

add_filter( 'gform_mailchimp_subscription', function( $subscription, $list_id, $form, $entry, $feed, $member ) {
	if ( ! $member ) {
		$today = date('m/d/y 23:59:59');
		$subscription['timestamp_signup'] = date( DATE_ATOM, strtotime($today));
	}
 
	return $subscription;
}, 10, 6 );

Anybody have any bright ideas? Vey grateful!

Hi @jamesdonegan
It looks like you are using a WordPress filter hook to try to modify the timestamp of the user’s registration in MailChimp. The code you provided should work if it is correctly implemented in your WordPress site.

To ensure the code is executed properly, you can try adding some debug statements to the function. For example, you could add a line at the beginning of the function to log the value of $subscription['timestamp_signup'] before you modify it. You could also add a line at the end of the function to log the modified value.

Another thing you could try is to use a different hook to modify the user’s registration time. The gform_mailchimp_subscription hook is used to modify the subscription data sent to MailChimp. If you want to modify the user’s registration time in your WordPress site before the subscription data is sent to MailChimp, you might want to use a different hook.

For example, you could use the gform_after_submission hook to modify the user’s registration time after the form submission is processed. This hook is triggered after the form submission has been processed but before any actions (such as sending the subscription data to MailChimp) are taken.

Here is an example of how you could modify the user’s registration time using the gform_after_submission hook:

add_action( 'gform_after_submission', function( $entry, $form ) {
 
    // Set the user's registration time to midnight
    $entry['date_created'] = date( 'Y-m-d 00:00:00', strtotime( $entry['date_created'] ) );
 
    // Update the entry with the modified registration time
    GFAPI::update_entry( $entry );
 
}, 10, 2 );

I hope this helps! Let me know if you have any questions or need further assistance.

Thank you. None of this is doing the trick because MailChimp still has to process the addition as soon as it’s received. As a result, I think my best short term bet (until they implement the feature I’ve requested) will be using something like this.

My question is what the trigger should be. I’m digging around in wp_schedule_event() to see if maybe I can delay all of the MailChimp feeds until like 11:59 each night. Seems possible.

Would love any thoughts!

Here is an update. I appreciate insights anyone may be able to offer…

// Delay processing of feed unless it's between midnight and 3am
add_filter( 'gform_is_delayed_pre_process_feed', 'jdf_delay_mailchimp_feeds', 10, 4 );
function jdf_delay_mailchimp_feeds( $is_delayed, $form, $entry, $slug ) {

	if ( $slug == 'gravityformsmailchimp' ) {

		$current_time = date('His');
		$midnight = '000000';
		$three = '030000';
		
		return ! ( ($time >  $midnight) && ($time < $three) );
	}
		
	return $is_delayed;

}

// schedule cron to run at 1 a.m. every day to process feeds
if ( ! wp_next_scheduled( 'jdf_cron_hook' ) ) {
	wp_schedule_event( strtotime('1am tomorrow'), 'daily', 'jdf_cron_hook' );
}

add_action( 'jdf_cron_hook', 'jdf_process_mailchimp' );
function jdf_process_mailchimp() {
	
	$feed = GFAPI::get_feeds( 2, 3, 'gravityformsmailchimp', true );
	$MailChimp = GFMailChimp::get_instance();
	$MailChimp->process_feed( $feed, $object->entry, $form );
	
	return;
}

Resolved via support ticket. Here is the code Jame shared with us:

// delay feed processing unless it's between midnight and 3 am
add_filter( 'gform_is_delayed_pre_process_feed', 'jdf_delay_mailchimp_feeds', 10, 4 );
function jdf_delay_mailchimp_feeds( $is_delayed, $form, $entry, $slug ) {

	if ( $slug == 'gravityformsmailchimp' ) {
		$reset = date_default_timezone_get();

		date_default_timezone_set('America/New_York');
		$current_time = date('His');
		$midnight = '000000';
		$three = '030000';
		date_default_timezone_set($reset);

		return ! ( ($current_time > $midnight) && ($current_time < $three) );
	}

	return $is_delayed;

}

// create schedule for CRON job for 1 a.m. Eastern
if ( ! wp_next_scheduled( 'jdf_cron_hook3' ) ) {
	$reset = date_default_timezone_get();
	date_default_timezone_set('America/New_York');
	wp_schedule_event( strtotime('01:00 am'), 'daily', 'jdf_cron_hook3' );
	date_default_timezone_set($reset);
	return;
}

// Add mailchimp process to Cron
add_action( 'jdf_cron_hook3', 'jdf_process_mailchimp' );
function jdf_process_mailchimp() {

	$form_id = 3;
	$form = GFAPI::get_form( $form_id );

	$search_criteria = array(
		'status' => 'active',
		'field_filters' => array(
		'mode' => 'any',
			array(
				'key' => 'jdf_feed_processed',
				'operator' => 'IS NOT',
				'value' => 'true'
			),
		),
	);
	$entries = GFAPI::get_entries( $form_id,$search_criteria );

	foreach ($entries as $entry):
		$entry_id = $entry['id'];
		gf_mailchimp()->maybe_process_feed( $entry, $form );
		gform_add_meta( $entry_id, 'jdf_feed_processed', 'true', $form_id );
		// after processing feed for the entry, add metadata to entry to note that it has been processed
	endforeach;

	return;
}