PluginProbe
Tiered Pricing Table for WooCommerce / 8.1.1
Tiered Pricing Table for WooCommerce v8.1.1
8.1.1 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 All 93 releases
tier-pricing-table / src / Addons / UserBasedPricing / UserBasedPricingRulesRepository.php

UserBasedPricingRulesRepository.php in Tiered Pricing Table for WooCommerce 8.1.1, at src/Addons/UserBasedPricing/UserBasedPricingRulesRepository.php

39 lines 1.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php namespace TierPricingTable\Addons\UserBasedPricing;
2
3 use TierPricingTable\TierPricingTablePlugin;
4 use WC_Product;
5
6 class UserBasedPricingRulesRepository {
7
8 protected static $instance;
9
10 public static function getInstance(): self {
11 if ( ! self::$instance ) {
12 self::$instance = new self();
13 }
14
15 return self::$instance;
16 }
17
18 public function getCurrentUserRule( WC_Product $product ): ?UserBasedPricingRule {
19
20 $userId = TierPricingTablePlugin::getCurrentUser()->ID; // honours the plugin's current-user filter (Pricing test)
21
22 if ( $userId ) {
23
24 if ( UserBasedPriceManager::userHasRules( $userId, $product->get_id() ) ) {
25 return UserBasedPricingRule::build( $product->get_id(), $userId );
26 }
27
28 // Check also for parent level
29 if ( TierPricingTablePlugin::isVariationProductSupported( $product ) ) {
30 if ( UserBasedPriceManager::userHasRules( $userId, $product->get_parent_id() ) ) {
31 return UserBasedPricingRule::build( $product->get_parent_id(), $userId );
32 }
33 }
34 }
35
36 return null;
37 }
38 }
39