AppliedCustomers.php
1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php namespace MeowCrew\RoleAndCustomerBasedPricing\GlobalRoleSpecificPricing\CPT\Columns;
use Exception;
use MeowCrew\RoleAndCustomerBasedPricing\Entity\GlobalPricingRule;
use MeowCrew\RoleAndCustomerBasedPricing\Utils\Formatter;
use WC_Customer;
class AppliedCustomers {
public function getName() {
return __( 'Customers', 'role-and-customer-based-pricing-for-woocommerce' );
}
public function render( GlobalPricingRule $rule ) {
$customersMoreThanCanBeShown = count( $rule->getIncludedUsers() ) > 10;
$appliedCustomersIds = array_slice( $rule->getIncludedUsers(), 0, 10 );
$appliedRoles = $rule->getIncludedUserRoles();
$appliedCustomers = array_filter( array_map( function ( $customerId ) {
try {
return new WC_Customer( $customerId );
} catch ( Exception $e ) {
return false;
}
}, $appliedCustomersIds ) );
if ( ! empty( $appliedRoles ) ) {
esc_html_e( 'Roles: ', 'role-and-customer-based-pricing-for-woocommerce' );
$appliedRolesString = array_map( function ( $role ) {
return sprintf( '<span>%s</span>', Formatter::formatRoleString( $role ) );
}, $appliedRoles );
echo wp_kses_post( implode( ', ', $appliedRolesString ) . '<br><br>' );
}
if ( ! empty( $appliedCustomers ) ) {
esc_html_e( 'Customers: ', 'role-and-customer-based-pricing-for-woocommerce' );
$appliedCustomersString = array_map( function ( WC_Customer $customer ) {
return Formatter::formatCustomerString( $customer, true );
}, $appliedCustomers );
echo wp_kses_post( implode( ', ', $appliedCustomersString ) . ( $customersMoreThanCanBeShown ? '<span> ...</span>' : '' ) );
}
if ( empty( $appliedRoles ) && empty( $appliedCustomers ) ) {
?>
<b style="color:#d63638"><?php esc_html_e( 'Applied to every user', 'role-and-customer-based-pricing-for-woocommerce' ); ?></b>
<?php
}
}
}