Last active
March 21, 2017 19:07
-
-
Save evrpress/1d94a8f15d54bc5b32be59eec2b4d86c to your computer and use it in GitHub Desktop.
Sends the first campaign of a drip campaign
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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