Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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