Skip to content

Instantly share code, notes, and snippets.

@evrpress
Last active March 21, 2017 19:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evrpress/1d94a8f15d54bc5b32be59eec2b4d86c to your computer and use it in GitHub Desktop.
Save evrpress/1d94a8f15d54bc5b32be59eec2b4d86c to your computer and use it in GitHub Desktop.
Sends the first campaign of a drip campaign
add_action( 'mailster_subscriber_subscribed', 'send_first_pregnancy_campaing' );
function send_first_pregnancy_campaing( $subscriber_id ) {
//get subscriber
if ( $subscriber = mailster( 'subscribers' )->get( $subscriber_id ) ) {
$seachstring = "Pregnancy week %d";
$total_weeks = 40;
//no birthdate
if ( !$subscriber->birthdate ) return;
$birthdate = strtotime( $subscriber->birthdate );
$diff = $birthdate-time();
$diff_in_weeks = $diff/60/60/24/7;
$pregnancy_week = floor( $total_weeks-$diff_in_weeks );
// birthdate reached or passed
if($pregnancy_week > $total_weeks) return;
//search for n autoresponder with the current week
if ( $campaigns = mailster( 'campaigns' )->get_autoresponder( array( 's' => sprintf( $seachstring, $pregnancy_week ) ) ) ) {
$campaign = $campaigns[0];
//send campaign
mailster( 'campaigns' )->send_to_subscriber( $campaign->ID, $subscriber->ID );
}else {
//no campaign found
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment