Skip to content

Commit

Permalink
fix(ras-sync): account for missing creation data and first/last name (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
dkoo authored Jan 21, 2025
1 parent ab4273e commit 9ed12bc
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions includes/reader-activation/sync/class-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,11 @@ public static function get_contact_from_customer( $customer, $payment_page_url =

$metadata = [];

$metadata['account'] = $customer->get_id();
$metadata['registration_date'] = $customer->get_date_created()->date( Metadata::DATE_FORMAT );
$customer_id = $customer->get_id();
$user = \get_user_by( 'id', $customer_id );
$created_date = $customer->get_date_created();
$metadata['account'] = $customer_id;
$metadata['registration_date'] = $created_date ? $created_date->date( Metadata::DATE_FORMAT ) : '';
$metadata['total_paid'] = $customer->get_total_spent();

$order = self::get_current_product_order_for_sync( $customer );
Expand All @@ -368,7 +371,16 @@ public static function get_contact_from_customer( $customer, $payment_page_url =
$first_name = $customer->get_billing_first_name();
$last_name = $customer->get_billing_last_name();
$full_name = trim( "$first_name $last_name" );
$contact = [

// Correct for empty First and Last Name fields.
if ( ! empty( trim( $first_name ) ) && empty( \get_user_meta( $customer_id, 'first_name', true ) ) ) {
\update_user_meta( $customer_id, 'first_name', $first_name );
}
if ( ! empty( trim( $last_name ) ) && empty( \get_user_meta( $customer_id, 'last_name', true ) ) ) {
\update_user_meta( $customer_id, 'last_name', $last_name );
}

$contact = [
'email' => $customer->get_email(),
'metadata' => $metadata,
];
Expand Down

0 comments on commit 9ed12bc

Please sign in to comment.