Skip to content
Merged
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
45 changes: 41 additions & 4 deletions inc/models/class-email.php
Original file line number Diff line number Diff line change
Expand Up @@ -575,15 +575,52 @@ public function get_target_list($payload = []) {
return [];
}

$customer = wu_get_customer($payload['customer_id']);
/*
* Try to get customer data from payload first.
* This prevents issues where wu_get_customer() might fail
* due to caching when the customer was just created.
*/
$customer_email = wu_get_isset($payload, 'customer_user_email');
$customer_name = wu_get_isset($payload, 'customer_name');

/*
* Ensure customer_name is a string, not an array or object.
*/
if (is_array($customer_name) || is_object($customer_name)) {
$customer_name = '';
}

/*
* If email is not in payload, fallback to database query.
*/
if ( ! $customer_email) {
$customer = wu_get_customer($payload['customer_id']);

if ( ! $customer) {
if ( ! $customer) {
return [];
}

$customer_email = $customer->get_email_address();
$customer_name = $customer->get_display_name();
}

/*
* Validate email before adding to target list.
*/
if ( ! is_email($customer_email)) {
return [];
}

/*
* Use email as name fallback if name is empty.
*/
if (empty($customer_name)) {
$customer_name = $customer_email;
}

$target_list[] = [
'name' => $customer->get_display_name(),
'email' => $customer->get_email_address(),
'name' => $customer_name,
'email' => $customer_email,
];

/*
Expand Down
Loading