| 1 |
<?php namespace TierPricingTable\Addons\GlobalTieredPricing; |
| 2 |
|
| 3 |
use WC_Customer; |
| 4 |
|
| 5 |
class Formatter { |
| 6 |
|
| 7 |
public static function formatCustomerString( WC_Customer $customer, $link = false ) { |
| 8 |
$firstName = $customer->get_billing_first_name() ? $customer->get_billing_first_name() : $customer->get_shipping_first_name(); |
| 9 |
$lastName = $customer->get_billing_last_name() ? $customer->get_billing_last_name() : $customer->get_shipping_last_name(); |
| 10 |
$email = $customer->get_billing_email() ? $customer->get_billing_email() : $customer->get_email(); |
| 11 |
|
| 12 |
if ( ! $email ) { |
| 13 |
return 'Undefined'; |
| 14 |
} |
| 15 |
|
| 16 |
$name = sprintf( '%s %s (%s)', $firstName, $lastName, $email ); |
| 17 |
|
| 18 |
if ( $link ) { |
| 19 |
return sprintf( '<a href="%s">%s</a>', get_edit_user_link( $customer->get_id() ), $name ); |
| 20 |
} |
| 21 |
|
| 22 |
return $name; |
| 23 |
} |
| 24 |
|
| 25 |
public static function formatRoleString( $roleSlug ) { |
| 26 |
$roles = wp_roles()->roles; |
| 27 |
|
| 28 |
if ( array_key_exists( $roleSlug, $roles ) ) { |
| 29 |
return $roles[ $roleSlug ]['name']; |
| 30 |
} |
| 31 |
|
| 32 |
return 'Undefined role'; |
| 33 |
} |
| 34 |
|
| 35 |
} |
| 36 |
|