| @@ -46,8 +46,9 @@ | ||
| 46 | 46 | 'last_name' => '', |
| 47 | 47 | 'email' => '', |
| 48 | 48 | 'phone' => '', |
| 49 | 49 | 'password' => '', |
| 50 | + 'quantity' => [] | |
| 50 | 51 | ]; |
| 51 | 52 | |
| 52 | 53 | /** |
| 53 | 54 | * Customer constructor |
| @@ -149,8 +150,46 @@ | ||
| 149 | 150 | return $user->user_pass; |
| 150 | 151 | } |
| 151 | 152 | |
| 152 | 153 | /** |
| 154 | + * Get quantity | |
| 155 | + * | |
| 156 | + * @return array | |
| 157 | + */ | |
| 158 | + public function get_quantity() { | |
| 159 | + $all_quantity = $this->get_prop( 'quantity' ); | |
| 160 | + $quantities = []; | |
| 161 | + if ( is_array( $all_quantity ) ){ | |
| 162 | + foreach( $all_quantity as $key => $quantity){ | |
| 163 | + $quantities[$key] = $quantity; | |
| 164 | + } | |
| 165 | + } | |
| 166 | + return $quantities; | |
| 167 | + | |
| 168 | + } | |
| 169 | + | |
| 170 | + /** | |
| 171 | + * Get Attendees | |
| 172 | + * | |
| 173 | + * @return array | |
| 174 | + */ | |
| 175 | + public function get_attendees() { | |
| 176 | + $all_attendees = $this->get_prop( 'attendees' ); | |
| 177 | + $attendees = []; | |
| 178 | + | |
| 179 | + if ( is_array( $all_attendees ) ) { | |
| 180 | + foreach( $all_attendees as $key => $attendee ) { | |
| 181 | + $attendees[] = [ | |
| 182 | + 'name' => $attendee['name'], | |
| 183 | + 'email' => $attendee['email'] | |
| 184 | + ]; | |
| 185 | + } | |
| 186 | + } | |
| 187 | + return $attendees; | |
| 188 | + | |
| 189 | + } | |
| 190 | + | |
| 191 | + /** | |
| 153 | 192 | * Get prop |
| 154 | 193 | * |
| 155 | 194 | * @param string |
| 156 | 195 | * |
| @@ -247,8 +286,16 @@ | ||
| 247 | 286 | 'user_login' => $this->data['email'], |
| 248 | 287 | 'user_email' => $this->data['email'], |
| 249 | 288 | ]; |
| 250 | 289 | |
| 290 | + $user_data = get_user_by( 'email', $this->data['email'] ); | |
| 291 | + | |
| 292 | + if ( $user_data && ! in_array( 'timetics-customer', $user_data->roles, true ) ) { | |
| 293 | + $user_data->add_role( 'timetics-customer' ); | |
| 294 | + | |
| 295 | + return $user_data->ID; | |
| 296 | + } | |
| 297 | + | |
| 251 | 298 | if ( $this->id ) { |
| 252 | 299 | $args['ID'] = $this->id; |
| 253 | 300 | $args['user_pass'] = $this->data['password']; |
| 254 | 301 | $customer_id = wp_update_user( $args ); |
| @@ -314,14 +361,19 @@ | ||
| 314 | 361 | |
| 315 | 362 | if ( email_exists( $args['email'] ) ) { |
| 316 | 363 | $user = get_user_by( 'email', $args['email'] ); |
| 317 | 364 | |
| 318 | - if ( ! $this->is_customer() ) { | |
| 365 | + if ( $user && ! in_array( 'timetics-customer', $user->roles, true ) ) { | |
| 319 | 366 | $user->add_role( 'timetics-customer' ); |
| 367 | + $this->set_id( $user->ID ); | |
| 368 | + | |
| 369 | + return $user->ID; | |
| 320 | 370 | } |
| 371 | + | |
| 321 | 372 | $this->set_id( $user->ID ); |
| 322 | 373 | $this->set_props( $args ); |
| 323 | - $this->save_metadata(); | |
| 374 | + $this->save_metadata( $args ); | |
| 375 | + | |
| 324 | 376 | } else { |
| 325 | 377 | $this->set_props( $args ); |
| 326 | 378 | $this->save(); |
| 327 | 379 | } |
| @@ -362,12 +414,19 @@ | ||
| 362 | 414 | * |
| 363 | 415 | * @return WP_Query |
| 364 | 416 | */ |
| 365 | 417 | private function booking_query() { |
| 418 | + // Not tied to "default_booking_status" (that's what status a NEW | |
| 419 | + // booking starts in, not which bookings count here) — otherwise an | |
| 420 | + // approved booking can vanish from the customer's count/history the | |
| 421 | + // moment it's approved, on any site where new bookings default to | |
| 422 | + // pending. See core/reports/api-report.php for the same fix. | |
| 423 | + $counted_statuses = apply_filters( 'timetics/report/counted_statuses', [ 'approved', 'completed' ] ); | |
| 424 | + | |
| 366 | 425 | $query = new \WP_Query( |
| 367 | 426 | [ |
| 368 | 427 | 'post_type' => 'timetics-booking', |
| 369 | - 'post_status' => 'completed', | |
| 428 | + 'post_status' => $counted_statuses, | |
| 370 | 429 | // @codingStandardsIgnoreStart |
| 371 | 430 | 'meta_key' => '_tt_booking_customer', |
| 372 | 431 | 'meta_value' => $this->id, |
| 373 | 432 | // @codingStandardsIgnoreEnd |