PluginProbe
Tiered Pricing Table for WooCommerce / 8.0.2
Tiered Pricing Table for WooCommerce v8.0.2
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 / views / addons / user-based-pricing / user-based-block.php

user-based-block.php in Tiered Pricing Table for WooCommerce 8.0.2, at views/addons/user-based-pricing/user-based-block.php

122 lines 4.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php defined( 'ABSPATH' ) || die;
2
3 use TierPricingTable\Addons\UserBasedPricing\ProductManager;
4 use TierPricingTable\Addons\UserBasedPricing\UserBasedPricingRule;
5 use TierPricingTable\Addons\UserBasedPricing\UserBasedPriceManager;
6 use TierPricingTable\Core\ServiceContainer;
7
8 /**
9 * Available variables
10 *
11 * @var int $product_id
12 * @var int $loop
13 */
14
15 $product = wc_get_product( $product_id );
16
17 if ( ! $product ) {
18 return;
19 }
20
21 $loop = ! is_null( $loop ) ? $loop : null;
22
23 $fileManager = ServiceContainer::getInstance()->getFileManager();
24
25 ?>
26
27 <div class="form-field tpt-user-based-block" id="tpt-user-based-block-<?php echo esc_attr( $product_id ); ?>"
28 data-product-type="<?php echo esc_attr( $product->get_type() ); ?>"
29 data-add-action="<?php echo esc_attr( ProductManager::GET_USER_ROW_HTML__ACTION ); ?>"
30 data-add-action-nonce="<?php echo esc_attr( wp_create_nonce( ProductManager::GET_USER_ROW_HTML__ACTION ) ); ?>"
31 data-product-id="<?php echo esc_attr( $product_id ); ?>"
32 data-loop="<?php echo esc_attr( $loop ); ?>">
33 <label class="tpt-user-based-block__name" style="line-height: normal"><?php esc_attr_e( 'Customer-Specific Pricing', 'tier-pricing-table' ); ?></label>
34 <div class="tpt-user-based-block__content">
35 <div class="tpt-user-based-users">
36 <?php
37
38 $presentUsers = array();
39
40 // We need to fetch users that have pricing. But we don't have a direct query for all users with this postmeta.
41 // However, we can query postmeta directly to find user IDs.
42 global $wpdb;
43 $meta_keys_like = $wpdb->esc_like( '_user_' ) . '%' . $wpdb->esc_like( '_tiered_price_rules_type' );
44 $results = $wpdb->get_results( $wpdb->prepare( "
45 SELECT meta_key FROM {$wpdb->postmeta}
46 WHERE post_id = %d AND meta_key LIKE %s
47 ", $product_id, $meta_keys_like ) );
48
49 foreach ( $results as $result ) {
50 // Extract user ID from meta_key (e.g. _user_123_tiered_price_rules_type)
51 if ( preg_match( '/^_user_(\d+)_tiered_price_rules_type$/', $result->meta_key, $matches ) ) {
52 $userId = (int) $matches[1];
53 $user = get_userdata( $userId );
54
55 if ( $user && UserBasedPriceManager::userHasRules( $userId, $product_id, 'edit' ) ) {
56
57 $userBasedRule = UserBasedPricingRule::build( $product_id, $userId );
58
59 $fileManager->includeTemplate( 'addons/user-based-pricing/user.php', array(
60 'pricing_rule' => $userBasedRule,
61 'user' => $user,
62 'product_id' => $product_id,
63 'product' => $product,
64 'loop' => $loop,
65 ) );
66
67 $presentUsers[] = $userId;
68 }
69 }
70 }
71 ?>
72 </div>
73
74 <div class="tpt-user-based-no-users"
75 style="<?php echo esc_attr( ! empty( $presentUsers ) ? 'display: none;' : '' ); ?>">
76 <span>
77 <?php
78 esc_attr_e( 'Set up specific pricing and rules for individual customers.',
79 'tier-pricing-table' );
80 ?>
81 </span>
82 <p class="description" style="display: block; margin: 0">
83 <?php
84 $settingsLink = add_query_arg( array(
85 'section' => 'advanced',
86 ), ServiceContainer::getInstance()->getSettings()->getLink() );
87
88 $settingsLink = sprintf( '<a target="_blank" href="%s">%s</a>', esc_url( $settingsLink ),
89 esc_html__( 'settings', 'tier-pricing-table' ) );
90 // translators: %s: settings link
91 echo wp_kses_post( sprintf( __( 'You can disable this feature in the %s if you don\'t need customer-based pricing.',
92 'tier-pricing-table' ), $settingsLink ) );
93
94 ?>
95
96 </p>
97 </div>
98
99 <div class="tpt-user-based-adding-form">
100 <select class="tpt-user-based-adding-form__user-selector wc-customer-search" data-placeholder="<?php esc_attr_e( 'Search for a customer&hellip;', 'woocommerce' ); ?>" data-allow_clear="true" style="width: 250px;">
101 </select>
102
103 <button class="button tpt-user-based-adding-form__add-button">
104 <?php
105 esc_attr_e( 'Add Customer', 'tier-pricing-table' );
106 ?>
107 </button>
108
109 <div class="clear"></div>
110 </div>
111
112 <?php $usersToDeleteName = ! is_null( $loop ) ? "tiered_price_rules_users_to_delete_variation[$loop][]" : 'tiered_price_rules_users_to_delete[]'; ?>
113
114 <select name="<?php echo esc_attr( $usersToDeleteName ); ?>" class="tiered_price_rules_users_to_delete" multiple
115 style="display:none;">
116 <?php foreach ( $presentUsers as $presentUserId ) : ?>
117 <option value="<?php echo esc_attr( $presentUserId ); ?>"><?php echo esc_attr( $presentUserId ); ?></option>
118 <?php endforeach; ?>
119 </select>
120 </div>
121 </div>
122