PluginProbe
Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO / 1.4.14
Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO v1.4.14
1.4.14 1.4.13 1.4.12 1.4.11 1.4.10 1.4.9 1.4.8 1.4.7 1.4.6 1.4.5 1.4.4 1.4.3 1.4.2 1.4.1 1.4.0 1.3.54 1.3.53 1.3.52 1.3.51 1.3.50 1.3.49 1.3.48 1.3.47 1.3.46 1.3.45 All 177 releases
disco / app / Attributes / Customer.php

Customer.php in Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO 1.4.14, at app/Attributes/Customer.php

157 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Product Attributes
4 *
5 * @package Disco
6 * @subpackage \App\Attributes
7 */
8
9 namespace Disco\App\Attributes;
10
11 use WC_Customer;
12
13 /**
14 * Class Product
15 *
16 * This class provides methods for retrieving various attributes of a WooCommerce product.
17 *
18 * @package Disco
19 * @subpackage \App\Attributes
20 * @author Ohidul Islam <wahid0003@gmail.com>
21 * @link https://webappick.com
22 * @license https://opensource.org/licenses/gpl-license.php GNU Public License
23 * @category Attributes
24 */
25 class Customer {
26
27 /**
28 * @var \WC_Customer|bool $customer Customer Object.
29 */
30 private $customer;
31
32 /**
33 * Customer constructor.
34 *
35 * @throws \Exception If the current user is not logged in.
36 */
37 public function __construct() {
38 if ( ! is_user_logged_in() ) {
39 $this->customer = false;
40 } else {
41 $this->customer = new WC_Customer( wp_get_current_user()->ID );
42 }
43 }
44
45 /**
46 * Get Customer ID
47 *
48 * @return string
49 */
50 public function customer_email() {
51 // If customer is not logged in, return empty string.
52 if ( ! $this->customer instanceof WC_Customer ) {
53 return '';
54 }
55
56 return $this->customer->get_email();
57 }
58
59 /**
60 * Get Customer Name
61 *
62 * @return string
63 */
64 public function customer_name() {
65 if ( $this->customer instanceof WC_Customer ) {
66 return $this->customer->get_first_name() . ' ' . $this->customer->get_last_name() . ' (' . $this->customer->get_email() . ')';
67 }
68
69 return '';
70 }
71
72 /**
73 * Get Customer is logged In
74 *
75 * @return string
76 */
77 public function customer_is_logged_in() {
78 if ( is_user_logged_in() ) {
79 return 'yes';
80 }
81
82 return 'no';
83 }
84
85 /**
86 * Get Customer Role
87 *
88 * @return string
89 */
90 public function customer_user_role() {
91 // If customer is not logged in, return empty string.
92 if ( ! $this->customer instanceof WC_Customer ) {
93 return '';
94 }
95
96 return $this->customer->get_role();
97 }
98
99 /**
100 * Get Customer Country
101 *
102 * @return string
103 */
104 public function customer_country() {
105 // If customer is not logged in, return empty string.
106 if ( ! $this->customer instanceof WC_Customer ) {
107 return '';
108 }
109
110 // woocommerce get country full name
111 return $this->customer->get_billing_country();
112 }
113
114 /**
115 * Get Customer City
116 *
117 * @return string
118 */
119 public function customer_city() {
120 // If customer is not logged in, return empty string.
121 if ( ! $this->customer instanceof WC_Customer ) {
122 return '';
123 }
124
125 return $this->customer->get_billing_city();
126 }
127
128 /**
129 * Get Customer State
130 *
131 * @return string
132 */
133 public function customer_state() {
134 // If customer is not logged in, return empty string.
135 if ( ! $this->customer instanceof WC_Customer ) {
136 return '';
137 }
138
139 return $this->customer->get_billing_state();
140 }
141
142 /**
143 * Get Customer Zip
144 *
145 * @return string
146 */
147 public function customer_zip() {
148 // If customer is not logged in, return empty string.
149 if ( ! $this->customer instanceof WC_Customer ) {
150 return '';
151 }
152
153 return $this->customer->get_billing_postcode();
154 }
155
156 }
157