Skip to content

Commit

Permalink
Now sending check pending admin emails at checkout
Browse files Browse the repository at this point in the history
  • Loading branch information
dparker1005 committed Sep 25, 2024
1 parent 198732d commit 9f135d5
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 2 deletions.
3 changes: 2 additions & 1 deletion classes/class.pmprogateway_pbc.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ function process(&$order) {
// Save the checkout data into the order.
pmpro_save_checkout_data_to_order( $order );

// Send the check_pending email.
// Send the check_pending emails.
pmpropbc_send_check_pending_email( $order );
pmpropbc_send_check_pending_admin_email( $order );

// Redirect to the confirmation page and await checkout completion.
$confirmation_url = apply_filters( 'pmpro_confirmation_url', add_query_arg( 'pmpro_level', $order->membership_level->id, pmpro_url("confirmation" ) ), $order->user_id, $order->membership_level );
Expand Down
88 changes: 87 additions & 1 deletion includes/emails.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@ function pmpropbc_email_template_to_pmproet_add_on( $template ) {
<p>Log in to your membership account here: !!login_link!!</p>', 'pmpro_pay_by_check' ),
);
$template['check_pending_admin'] = array(
'subject' => 'Pending checkout for !!display_name!! at !!sitename!!',
'description' => 'Pay By Check - Check Pending Admin',
'body' => __( '<p>There is a pending checkout at !!sitename!!.</p>
<p>Account: !!display_name!! (!!user_email!!)</p>
<p>Membership Level: !!membership_level_name!!</p>
<p>
Invoice #!!invoice_id!! on !!invoice_date!!<br />
Total Billed: !!invoice_total!!
</p>', 'pmpro_pay_by_check' ),
);
$template['check_pending_reminder'] = array(
'subject' => 'Reminder: New Invoice for !!display_name!! at !!sitename!!',
'description' => 'Pay By Check - Check Pending Reminder',
Expand Down Expand Up @@ -115,7 +128,80 @@ function pmpropbc_send_check_pending_email( $order ) {
$order->billing->phone);

if($order->getDiscountCode())
$email->data["discount_code"] = "<p>" . __("Discount Code", "pmpro") . ": " . $order->discount_code->code . "</p>\n";
$email->data["discount_code"] = "<p>" . __("Discount Code", "pmpro-pay-by-check") . ": " . $order->discount_code->code . "</p>\n";
else
$email->data["discount_code"] = "";

//send the email
return $email->sendEmail();
}

/**
* Send the check_pending_admin email.
*
* @since TBD
*
* @param MemberOrder $order - The order object.
* @return bool - True if the email was sent, false otherwise.
*/
function pmpropbc_send_check_pending_admin_email( $order ) {
// Get the user.
$user = get_userdata( $order->user_id );
if ( empty( $user ) ) {
return false;
}

// Get the membership level.
$level = $order->getMembershipLevel();
if ( empty( $level ) ) {
return false;
}

$email = new PMProEmail();
$email->template = "check_pending_admin";
$email->email = get_bloginfo("admin_email");
$email->subject = sprintf(__("Pending checkout for !!display_name!! at !!sitename!!", "pmpro-pay-by-check"), $level->name, get_option("blogname"));

//setup more data
$email->data = array(
"name" => $user->display_name,
"user_login" => $user->user_login,
"sitename" => get_option("blogname"),
"siteemail" => pmpro_getOption("from_email"),
"membership_id" => $level->id,
"membership_level_name" => $level->name,
"membership_cost" => pmpro_getLevelCost( $level ),
"login_link" => wp_login_url(pmpro_url("account")),
"display_name" => $user->display_name,
"user_email" => $user->user_email,
);

$email->data["instructions"] = wp_unslash( pmpro_getOption('instructions') );
$email->data["invoice_id"] = $order->code;
$email->data["invoice_total"] = pmpro_formatPrice($order->total);
$email->data["invoice_date"] = date(get_option('date_format'), $order->timestamp);
$email->data["billing_name"] = $order->billing->name;
$email->data["billing_street"] = $order->billing->street;
$email->data["billing_city"] = $order->billing->city;
$email->data["billing_state"] = $order->billing->state;
$email->data["billing_zip"] = $order->billing->zip;
$email->data["billing_country"] = $order->billing->country;
$email->data["billing_phone"] = $order->billing->phone;
$email->data["cardtype"] = $order->cardtype;
$email->data["accountnumber"] = hideCardNumber($order->accountnumber);
$email->data["expirationmonth"] = $order->expirationmonth;
$email->data["expirationyear"] = $order->expirationyear;
$email->data["billing_address"] = pmpro_formatAddress($order->billing->name,
$order->billing->street,
"", //address 2
$order->billing->city,
$order->billing->state,
$order->billing->zip,
$order->billing->country,
$order->billing->phone);

if($order->getDiscountCode())
$email->data["discount_code"] = "<p>" . __("Discount Code", "pmpro-pay-by-check") . ": " . $order->discount_code->code . "</p>\n";
else
$email->data["discount_code"] = "";

Expand Down

0 comments on commit 9f135d5

Please sign in to comment.