PluginProbe
Easy Invoice – Invoice Generator, PDF Quotes & Payments / 2.1.2
Easy Invoice – Invoice Generator, PDF Quotes & Payments v2.1.2
2.4.0 2.4.1 2.3.8 2.3.7 2.3.6 2.3.5 2.3.4 2.3.3 2.3.2 2.3.1 2.2.0 2.1.21 2.1.20 2.1.19 2.1.18 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 2.1.15 2.1.16 2.1.2 All 57 releases
easy-invoice / includes / Helpers / ClientDisplayHelper.php

ClientDisplayHelper.php in Easy Invoice – Invoice Generator, PDF Quotes & Payments 2.1.2, at includes/Helpers/ClientDisplayHelper.php

91 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Client Display Helper
4 *
5 * @package EasyInvoice
6 * @subpackage Helpers
7 * @since 2.0.0
8 */
9
10 namespace EasyInvoice\Helpers;
11
12 /**
13 * Helper class for displaying client information with fallback logic
14 */
15 class ClientDisplayHelper {
16
17 /**
18 * Get display name for client with fallback logic
19 *
20 * Priority: business_client_name > first_name + last_name > display_name
21 *
22 * @param int $client_id WordPress user ID
23 * @return string Client display name
24 */
25 public static function getClientDisplayName(int $client_id): string {
26 if ($client_id <= 0) {
27 return '';
28 }
29
30 $user = get_user_by('id', $client_id);
31 if (!$user) {
32 return '';
33 }
34
35 // First priority: Business/Client Name
36 $business_name = get_user_meta($client_id, 'easy_invoice_business_client_name', true);
37 if (!empty($business_name)) {
38 return $business_name;
39 }
40
41 // Second priority: First Name + Last Name
42 $first_name = get_user_meta($client_id, 'first_name', true);
43 $last_name = get_user_meta($client_id, 'last_name', true);
44
45 if (!empty($first_name) || !empty($last_name)) {
46 $full_name = trim($first_name . ' ' . $last_name);
47 if (!empty($full_name)) {
48 return $full_name;
49 }
50 }
51
52 // Third priority: WordPress display name
53 if (!empty($user->display_name)) {
54 return $user->display_name;
55 }
56
57 // Last resort: Username
58 return $user->user_login;
59 }
60
61 /**
62 * Get client display name for invoice or quote
63 *
64 * @param \EasyInvoice\Models\Invoice|\EasyInvoice\Models\Quote $document
65 * @return string Client display name
66 */
67 public static function getDocumentClientDisplayName($document): string {
68 if (!$document) {
69 return '';
70 }
71
72 // Try to get customer name directly from document
73 if (method_exists($document, 'getCustomerName')) {
74 $customer_name = $document->getCustomerName();
75 if (!empty($customer_name)) {
76 return $customer_name;
77 }
78 }
79
80 // Fallback to client ID lookup
81 if (method_exists($document, 'getClientId')) {
82 $client_id = $document->getClientId();
83 if ($client_id > 0) {
84 return self::getClientDisplayName($client_id);
85 }
86 }
87
88 return '';
89 }
90 }
91