Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

* Add checkout templates #3202

Open
wants to merge 1 commit into
base: enhancement/email-template-abstraction
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
214 changes: 42 additions & 172 deletions classes/class.pmproemail.php
Original file line number Diff line number Diff line change
Expand Up @@ -595,102 +595,35 @@ function sendCheckoutEmail($user = NULL, $order = NULL)
return false;
}

$membership_level = pmpro_getSpecificMembershipLevelForUser($user->ID, $order->membership_id);

$confirmation_in_email = get_pmpro_membership_level_meta( $membership_level->id, 'confirmation_in_email', true );
if ( ! empty( $confirmation_in_email ) ) {
$confirmation_message = $membership_level->confirmation;
$email = null;
if( !empty( $this->template ) ) {
switch ( $this->template ) {
case 'checkout_check':
$email = new PMPro_Email_Template_Checkout_Check( $user, $order );
break;
case 'checkout_free':
$email = new PMPro_Email_Template_Checkout_Free( $user, $order );
break;
case 'checkout_paid':
$email = new PMPro_Email_Template_Checkout_Paid( $user, $order );
break;
}
} else {
$confirmation_message = '';
}

$this->email = $user->user_email;
$this->subject = sprintf(__("Your membership confirmation for %s", 'paid-memberships-pro' ), get_option("blogname"));

$this->data = array(
'subject' => $this->subject,
'header_name' => $user->display_name,
'name' => $user->display_name,
'display_name' => $user->display_name,
'user_login' => $user->user_login,
'sitename' => get_option('blogname'),
'siteemail' => get_option('pmpro_from_email'),
'membership_id' => $membership_level->id,
'membership_level_name' => $membership_level->name,
'membership_level_confirmation_message' => wpautop( $confirmation_message ),
'membership_cost' => pmpro_getLevelCost($membership_level),
'login_link' => pmpro_login_url(),
'login_url' => pmpro_login_url(),
'user_email' => $user->user_email,
'levels_url' => pmpro_url( 'levels' )
);

// Figure out which template to use.
if ( empty( $this->template ) ) {
if( ! empty( $order ) && ! pmpro_isLevelFree( $membership_level ) ) {
if( $order->gateway == "check" ) {
$this->template = "checkout_check";
$email = new PMPro_Email_Template_Checkout_Check( $user, $order );
} else {
$this->template = "checkout_paid";
}
$email = new PMPro_Email_Template_Checkout_Paid( $user, $order );
}
} elseif( pmpro_isLevelFree( $membership_level ) ) {
$this->template = "checkout_free";
$email = new PMPro_Email_Template_Checkout_Free( $user, $order );
}
}

$this->template = apply_filters( "pmpro_email_template", $this->template, $this );

// Gather data depending on template being used.
if( in_array( $this->template, array( 'checkout_check', 'checkout_paid' ) ) ) {
if( $this->template === 'checkout_check' ) {
$this->data["instructions"] = wpautop( get_option( "pmpro_instructions" ) );
}

$this->data["order_id"] = $order->code;
$this->data["order_total"] = $order->get_formatted_total();
$this->data["order_date"] = date_i18n( get_option( 'date_format' ), $order->getTimestamp() );
$this->data["billing_name"] = $order->billing->name;
$this->data["billing_street"] = $order->billing->street;
$this->data["billing_street2"] = $order->billing->street2;
$this->data["billing_city"] = $order->billing->city;
$this->data["billing_state"] = $order->billing->state;
$this->data["billing_zip"] = $order->billing->zip;
$this->data["billing_country"] = $order->billing->country;
$this->data["billing_phone"] = $order->billing->phone;
$this->data["cardtype"] = $order->cardtype;
$this->data["accountnumber"] = hideCardNumber($order->accountnumber);
$this->data["expirationmonth"] = $order->expirationmonth;
$this->data["expirationyear"] = $order->expirationyear;
$this->data["billing_address"] = pmpro_formatAddress($order->billing->name,
$order->billing->street,
$order->billing->street2,
$order->billing->city,
$order->billing->state,
$order->billing->zip,
$order->billing->country,
$order->billing->phone);

if( $order->getDiscountCode() ) {
$this->data["discount_code"] = "<p>" . __("Discount Code", 'paid-memberships-pro' ) . ": " . $order->discount_code->code . "</p>\n";
} else {
$this->data["discount_code"] = "";
}
} elseif( $this->template === 'checkout_free' ) {
if( ! empty( $discount_code ) ) {
$this->data["discount_code"] = "<p>" . __("Discount Code", 'paid-memberships-pro' ) . ": " . $discount_code . "</p>\n";
} else {
$this->data["discount_code"] = "";
}
//Bail if $email is null
if( $email == null ) {
return false;
}

$enddate = $wpdb->get_var("SELECT UNIX_TIMESTAMP(CONVERT_TZ(enddate, '+00:00', @@global.time_zone)) FROM $wpdb->pmpro_memberships_users WHERE user_id = '" . $user->ID . "' AND status = 'active' LIMIT 1");
if( $enddate ) {
$this->data["membership_expiration"] = "<p>" . sprintf(__("This membership will expire on %s.", 'paid-memberships-pro' ), date_i18n(get_option('date_format'), $enddate)) . "</p>\n";
} else {
$this->data["membership_expiration"] = "";
}

return $this->sendEmail();
$email->send();
}

/**
Expand All @@ -712,100 +645,37 @@ function sendCheckoutAdminEmail($user = NULL, $order = NULL)
return false;
}

$membership_level = pmpro_getSpecificMembershipLevelForUser($user->ID, $order->membership_id);

$confirmation_in_email = get_pmpro_membership_level_meta( $membership_level->id, 'confirmation_in_email', true );
if ( ! empty( $confirmation_in_email ) ) {
$confirmation_message = $membership_level->confirmation;
$email = null;
if( !empty( $this->template ) ) {
switch( $this->template ) {
case 'checkout_check_admin':
$email = new PMPro_Email_Template_Checkout_Check_Admin( $user, $order );
break;
case 'checkout_free_admin':
$email = new PMPro_Email_Template_Checkout_Free_Admin( $user, $order );
break;
case 'checkout_paid':
$email = new PMPro_Email_Template_Checkout_Paid_Admin( $user, $order );
break;
}
} else {
$confirmation_message = '';
}

$this->email = get_bloginfo("admin_email");
$this->subject = sprintf(__("Member checkout for %s at %s", 'paid-memberships-pro' ), $membership_level->name, get_option("blogname"));

$this->data = array(
'subject' => $this->subject,
'header_name' => $this->get_admin_name( $this->email ),
'name' => $user->display_name,
'user_login' => $user->user_login,
'sitename' => get_option( 'blogname' ),
'siteemail' => get_option( 'pmpro_from_email' ),
'membership_id' => $membership_level->id,
'membership_level_name' => $membership_level->name,
'membership_level_confirmation_message' => $confirmation_message,
'membership_cost' => pmpro_getLevelCost($membership_level),
'login_link' => pmpro_login_url(),
'login_url' => pmpro_login_url(),
'display_name' => $user->display_name,
'user_email' => $user->user_email,
'levels_url' => pmpro_url( 'levels' )
);

// Figure out which template to use.
if ( empty( $this->template ) ) {
if( ! empty( $order ) && ! pmpro_isLevelFree( $membership_level ) ) {
if( $order->gateway == "check" ) {
$this->template = "checkout_check_admin";
$email = new PMPro_Email_Template_Checkout_Check_Admin( $user, $order );
} else {
$this->template = "checkout_paid_admin";
$email = new PMPro_Email_Template_Checkout_Paid_Admin( $user, $order );
}
} elseif( pmpro_isLevelFree( $membership_level ) ) {
$this->template = "checkout_free_admin";
$email = new PMPro_Email_Template_Checkout_Free_Admin( $user, $order );
}
}

$this->template = apply_filters( "pmpro_email_template", $this->template, $this );

// Gather data depending on template being used.
if( in_array( $this->template, array( 'checkout_check_admin', 'checkout_paid_admin' ) ) ) {
$this->data["order_id"] = $order->code;
$this->data["order_total"] = $order->get_formatted_total();
$this->data["order_date"] = date_i18n(get_option('date_format'), $order->getTimestamp());
$this->data["billing_name"] = $order->billing->name;
$this->data["billing_street"] = $order->billing->street;
$this->data["billing_street2"] = $order->billing->street2;
$this->data["billing_city"] = $order->billing->city;
$this->data["billing_state"] = $order->billing->state;
$this->data["billing_zip"] = $order->billing->zip;
$this->data["billing_country"] = $order->billing->country;
$this->data["billing_phone"] = $order->billing->phone;
$this->data["cardtype"] = $order->cardtype;
$this->data["accountnumber"] = hideCardNumber($order->accountnumber);
$this->data["expirationmonth"] = $order->expirationmonth;
$this->data["expirationyear"] = $order->expirationyear;
$this->data["billing_address"] = pmpro_formatAddress($order->billing->name,
$order->billing->street,
$order->billing->street2,
$order->billing->city,
$order->billing->state,
$order->billing->zip,
$order->billing->country,
$order->billing->phone);

if( $order->getDiscountCode() ) {
$this->data["discount_code"] = "<p>" . __("Discount Code", 'paid-memberships-pro' ) . ": " . $order->discount_code->code . "</p>\n";
} else {
$this->data["discount_code"] = "";
}
} elseif( $this->template === 'checkout_free_admin' ) {
if( ! empty( $discount_code ) ) {
$this->data["discount_code"] = "<p>" . __("Discount Code", 'paid-memberships-pro' ) . ": " . $discount_code . "</p>\n";
} else {
$this->data["discount_code"] = "";
}
}

$enddate = $wpdb->get_var("SELECT UNIX_TIMESTAMP(CONVERT_TZ(enddate, '+00:00', @@global.time_zone)) FROM $wpdb->pmpro_memberships_users WHERE user_id = '" . $user->ID . "' AND status = 'active' LIMIT 1");
if( $enddate ) {
$this->data["membership_expiration"] = "<p>" . sprintf(__("This membership will expire on %s.", 'paid-memberships-pro' ), date_i18n(get_option('date_format'), $enddate)) . "</p>\n";
} else {
$this->data["membership_expiration"] = "";
//Bail if $email is null
if( $email == null ) {
return false;
}

return $this->sendEmail();
$email->send();
}

/**
* Send the member a confirmation email when updating their billing details
*
Expand Down
Loading