PluginProbe
Tiered Pricing Table for WooCommerce / trunk
Tiered Pricing Table for WooCommerce vtrunk
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 2.3.4 All 90 releases
tier-pricing-table / src / Addons / UserBasedPricing / UserBasedPricingRulesRepository.php

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

39 lines 961 B
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 = get_current_user_id();
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