PluginProbe
Tiered Pricing Table for WooCommerce / 6.1.0
Tiered Pricing Table for WooCommerce v6.1.0
8.0.2 7.1.7 7.1.5 7.1.4 7.1.1 6.5.0 6.4.0 6.1.0 trunk 1.0 1.1 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.2.0 2.2.1 2.2.2 2.2.3 2.3.0 2.3.1 2.3.2 2.3.3 All 91 releases
tier-pricing-table / src / Addons / GlobalTieredPricing / CPT / Columns / AppliedCustomers.php

AppliedCustomers.php in Tiered Pricing Table for WooCommerce 6.1.0, at src/Addons/GlobalTieredPricing/CPT/Columns/AppliedCustomers.php

92 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php namespace TierPricingTable\Addons\GlobalTieredPricing\CPT\Columns;
2
3 use Exception;
4 use TierPricingTable\Addons\GlobalTieredPricing\GlobalPricingRule;
5 use TierPricingTable\Addons\GlobalTieredPricing\Formatter;
6 use WC_Customer;
7
8 class AppliedCustomers {
9
10 public function getName(): string {
11 return __( 'Users & Roles', 'tier-pricing-table' );
12 }
13
14 public function render( GlobalPricingRule $rule ) {
15
16 $hasCustomers = $this->showCustomers( $rule->getIncludedUsers() );
17 $hasRoles = $this->showUserRoles( $rule->getIncludedUserRoles() );
18
19 if ( ! $hasRoles && ! $hasCustomers ) {
20 ?>
21 <mark class="order-status status-processing tips">
22 <span>
23 <?php esc_html_e( 'Applied to every user', 'tier-pricing-table' ); ?>
24 </span>
25 </mark>
26 <?php
27 }
28
29 $this->showCustomers( $rule->getExcludedUsers(), false );
30 $this->showUserRoles( $rule->getExcludedUserRoles(), false );
31 }
32
33 public function showCustomers( array $customersIds, $included = true ): bool {
34 $customersMoreThanCanBeShown = count( $customersIds ) > 10;
35
36 $customersIds = array_slice( $customersIds, 0, 5 );
37
38 $customers = array_filter( array_map( function ( $customerId ) {
39 try {
40 return new WC_Customer( $customerId );
41 } catch ( Exception $e ) {
42 return false;
43 }
44 }, $customersIds ) );
45
46 if ( ! empty( $customers ) ) {
47
48 if ( $included ) {
49 esc_html_e( 'Customers: ', 'tier-pricing-table' );
50 } else {
51 esc_html_e( 'Excluded customers: ', 'tier-pricing-table' );
52 }
53
54 $customersString = array_map( function ( WC_Customer $customer ) {
55 return Formatter::formatCustomerString( $customer, true );
56 }, $customers );
57
58 echo wp_kses_post( implode( ', ',
59 $customersString ) . ( $customersMoreThanCanBeShown ? '<span> ...</span>' : '' ) );
60
61 echo '<br><br>';
62
63 return true;
64 }
65
66 return false;
67 }
68
69 public function showUserRoles( array $roles, $included = true ): bool {
70
71 if ( ! empty( $roles ) ) {
72 if ( $included ) {
73 esc_html_e( 'Roles: ', 'tier-pricing-table' );
74 } else {
75 esc_html_e( 'Excluded roles: ', 'tier-pricing-table' );
76 }
77
78 $rolesString = array_map( function ( $role ) {
79 return sprintf( '<span>%s</span>', Formatter::formatRoleString( $role ) );
80 }, $roles );
81
82 echo wp_kses_post( implode( ', ', $rolesString ) );
83
84 echo '<br><br>';
85
86 return true;
87 }
88
89 return false;
90 }
91 }
92