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 / RoleBasedPricing / RoleBasedPricingRulesRepository.php

RoleBasedPricingRulesRepository.php in Tiered Pricing Table for WooCommerce 6.1.0, at src/Addons/RoleBasedPricing/RoleBasedPricingRulesRepository.php

41 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\RoleBasedPricing;
2
3 use TierPricingTable\TierPricingTablePlugin;
4 use WC_Product;
5
6 class RoleBasedPricingRulesRepository {
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 ): ?RoleBasedPricingRule {
19
20 $userRoles = TierPricingTablePlugin::getCurrentUserRoles();
21
22 if ( ! empty( $userRoles ) ) {
23
24 foreach ( $userRoles as $role ) {
25 if ( RoleBasedPriceManager::roleHasRules( $role, $product->get_id() ) ) {
26 return RoleBasedPricingRule::build( $product->get_id(), $role );
27 }
28
29 // Check also for parent level
30 if ( TierPricingTablePlugin::isVariationProductSupported( $product ) ) {
31 if ( RoleBasedPriceManager::roleHasRules( $role, $product->get_parent_id() ) ) {
32 return RoleBasedPricingRule::build( $product->get_parent_id(), $role );
33 }
34 }
35 }
36 }
37
38 return null;
39 }
40 }
41