PluginProbe
Tiered Pricing Table for WooCommerce / 8.1.0
Tiered Pricing Table for WooCommerce v8.1.0
8.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 All 92 releases
tier-pricing-table / src / Addons / GlobalTieredPricing / CPT / Form / Tabs / UsersAndRoles.php

UsersAndRoles.php in Tiered Pricing Table for WooCommerce 8.1.0, at src/Addons/GlobalTieredPricing/CPT/Form/Tabs/UsersAndRoles.php

139 lines 4.7 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\Form\Tabs;
2
3 use TierPricingTable\Addons\GlobalTieredPricing\CPT\Form\FormTab;
4 use TierPricingTable\Addons\GlobalTieredPricing\Formatter;
5 use TierPricingTable\Addons\GlobalTieredPricing\GlobalPricingRule;
6 use TierPricingTable\Core\ServiceContainer;
7
8 class UsersAndRoles extends FormTab {
9
10 public function getId(): string {
11 return 'user-and-roles';
12 }
13
14 public function getTitle(): string {
15 return __( 'Users & Roles', 'tier-pricing-table' );
16 }
17
18 public function getDescription(): string {
19 return __( 'Select the users or roles this rule applies to', 'tier-pricing-table' );
20 }
21
22 public function render( GlobalPricingRule $pricingRule ) {
23
24 $this->renderSectionTitle( __( 'Applies to users', 'tier-pricing-table' ) );
25
26 if ( empty( $pricingRule->getIncludedUserRoles() ) && empty( $pricingRule->getIncludedUsers() ) ) {
27 $this->renderHint( __( 'The rule will apply to all users if you do not specify user roles or specific customers (excluding those selected in the exclusions section).',
28 'tier-pricing-table' ) );
29 }
30
31 $this->renderSelect2( array(
32 'id' => 'tpt_included_user_roles',
33 'label' => __( 'User roles', 'tier-pricing-table' ),
34 'options' => ( function () {
35 return array( GlobalPricingRule::GUEST_ROLE => __( 'Guests (not logged in)', 'tier-pricing-table' ) ) + array_map( function ( $WPRole ) {
36 return $WPRole['name'];
37 }, wp_roles()->roles );
38 } )(),
39 'value' => $pricingRule->getIncludedUserRoles(),
40 'placeholder' => __( 'Select for a user role', 'tier-pricing-table' ),
41 'css_class' => 'tpt-select-woo',
42 'desc_tip' => false,
43 'description' => function () {
44 $settingsLink = ServiceContainer::getInstance()->getSettings()->getLink();
45
46 $settingsLink = add_query_arg( [
47 'section' => 'advanced',
48 ], $settingsLink );
49
50 $settingsLink .= '#roles';
51
52 ?>
53 <a href="<?php echo esc_url( $settingsLink ); ?>"
54 target="_blank"><?php esc_html_e( 'Manage user roles', 'tier-pricing-table' ); ?></a>
55 <?php
56 },
57 ) );
58
59
60 $this->renderSelect2( array(
61 'id' => 'tpt_included_users',
62 'label' => __( 'Customers', 'tier-pricing-table' ),
63 'options' => ( function () use ( $pricingRule ) {
64 $users = [];
65 foreach ( $pricingRule->getIncludedUsers() as $userId ) {
66 $customer = new \WC_Customer( $userId );
67
68 if ( $customer->get_id() ) {
69 $users[ $userId ] = Formatter::formatCustomerString( $customer );
70 }
71 }
72
73 return $users;
74 } )(),
75 'value' => $pricingRule->getIncludedUsers(),
76 'placeholder' => __( 'Select for a customer', 'tier-pricing-table' ),
77 'search_action' => 'woocommerce_json_search_tpt_customers',
78 'css_class' => 'rbp-select-woo wc-product-search',
79 ) );
80
81 $hasExclusions = ! empty( $pricingRule->getExcludedUserRoles() ) ||
82 ! empty( $pricingRule->getExcludedUsers() );
83 ?>
84 <details class="tpt-exclusions-accordion" <?php echo $hasExclusions ? 'open' : ''; ?>>
85 <summary>
86 <?php echo esc_html__( 'Exclusions', 'tier-pricing-table' ); ?>
87 <span class="dashicons dashicons-arrow-down-alt2 tpt-accordion-icon"></span>
88 </summary>
89 <div class="tpt-exclusions-accordion-content">
90 <?php
91
92 $this->renderSelect2( array(
93 'id' => 'tpt_excluded_user_roles',
94 'label' => __( 'User roles', 'tier-pricing-table' ),
95 'options' => ( function () {
96 $roles = array( GlobalPricingRule::GUEST_ROLE => __( 'Guests (not logged in)', 'tier-pricing-table' ) );
97 foreach ( wp_roles()->roles as $key => $WPRole ) {
98 $roles[ $key ] = $WPRole['name'];
99 }
100
101 return $roles;
102 } )(),
103 'value' => $pricingRule->getExcludedUserRoles(),
104 'placeholder' => __( 'Select for a user role', 'tier-pricing-table' ),
105 'css_class' => 'tpt-select-woo',
106 ) );
107
108 $this->renderSelect2( array(
109 'id' => 'tpt_excluded_users',
110 'label' => __( 'Customers', 'tier-pricing-table' ),
111 'options' => ( function () use ( $pricingRule ) {
112 $users = [];
113 foreach ( $pricingRule->getExcludedUsers() as $userId ) {
114 $customer = new \WC_Customer( $userId );
115
116 if ( $customer->get_id() ) {
117 $users[ $userId ] = Formatter::formatCustomerString( $customer );
118 }
119 }
120
121 return $users;
122 } )(),
123 'value' => $pricingRule->getExcludedUsers(),
124 'placeholder' => __( 'Select for a customer', 'tier-pricing-table' ),
125 'search_action' => 'woocommerce_json_search_tpt_customers',
126 'css_class' => 'rbp-select-woo wc-product-search',
127 ) );
128
129 ?>
130 </div>
131 </details>
132 <?php
133 }
134
135 public function getIcon(): string {
136 return 'dashicons-admin-users';
137 }
138 }
139