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 / GlobalTieredPricing / PricingRule / RuleSettings.php

RuleSettings.php in Tiered Pricing Table for WooCommerce 6.1.0, at src/Addons/GlobalTieredPricing/PricingRule/RuleSettings.php

105 lines 4.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php namespace TierPricingTable\Addons\GlobalTieredPricing\PricingRule;
2
3 use TierPricingTable\Addons\GlobalTieredPricing\GlobalPricingRule;
4
5 class RuleSettings {
6
7 protected $priorityType = 'default';
8
9 protected $tieredPricingPriority = 'prefer-product';
10 protected $allowTieredPricingMixAndMatch = false;
11
12 protected $regularPricingPriority = 'prefer-role-based-product';
13
14 protected $quantityLimitsPriority = 'prefer-product';
15
16 public function __construct( GlobalPricingRule $pricingRule ) {
17 $tieredPricingPriority = get_post_meta( $pricingRule->getId(),
18 '_tpt_settings_tiered_pricing_priority_type', true );
19 $allowTieredPricingMixAndMatch = get_post_meta( $pricingRule->getId(),
20 '_tpt_settings_tiered_pricing_allow_mix_and_match', true ) === 'yes';
21
22 $regularPricingPriority = get_post_meta( $pricingRule->getId(), '_tpt_settings_regular_pricing_priority_type',
23 true );
24 $quantityLimitsPriority = get_post_meta( $pricingRule->getId(), '_tpt_settings_quantity_limits_priority_type',
25 true );
26 $priorityType = get_post_meta( $pricingRule->getId(), '_tpt_settings_priority_type', true );
27
28 $this->setTieredPricingPriority( $tieredPricingPriority );
29 $this->setAllowTieredPricingMixAndMatch( $allowTieredPricingMixAndMatch );
30
31 $this->setRegularPricingPriority( $regularPricingPriority );
32 $this->setQuantityLimitsPriority( $quantityLimitsPriority );
33
34 $this->setPriorityType( $priorityType );
35 }
36
37 public function getPriorityType(): string {
38 return $this->priorityType;
39 }
40
41 public function setPriorityType( string $priorityType ): void {
42
43 if ( in_array( $priorityType, array( 'default', 'prefer-product', 'override', 'flexible' ) ) ) {
44 $this->priorityType = $priorityType;
45 }
46 }
47
48 public function getQuantityLimitsPriority(): string {
49 return $this->quantityLimitsPriority;
50 }
51
52 public function setQuantityLimitsPriority( string $quantityLimitsPriority ): void {
53 if ( in_array( $quantityLimitsPriority, array( 'prefer-product', 'prefer-role-based-product', 'override' ) ) ) {
54 $this->quantityLimitsPriority = $quantityLimitsPriority;
55 }
56 }
57
58 public function getTieredPricingPriority(): string {
59 return $this->tieredPricingPriority;
60 }
61
62 public function setTieredPricingPriority( string $tieredPricingPriority ): void {
63 if ( in_array( $tieredPricingPriority, array( 'prefer-product', 'prefer-role-based-product', 'override' ) ) ) {
64 $this->tieredPricingPriority = $tieredPricingPriority;
65 }
66 }
67
68 public function isAllowTieredPricingMixAndMatch(): bool {
69 return $this->allowTieredPricingMixAndMatch;
70 }
71
72 public function setAllowTieredPricingMixAndMatch( bool $allowTieredPricingMixAndMatch ): void {
73 $this->allowTieredPricingMixAndMatch = $allowTieredPricingMixAndMatch;
74 }
75
76 public function getRegularPricingPriority(): string {
77 return $this->regularPricingPriority;
78 }
79
80 public function setRegularPricingPriority( string $regularPricingPriority ): void {
81 if ( in_array( $regularPricingPriority, array( 'prefer-role-based-product', 'override' ) ) ) {
82 $this->regularPricingPriority = $regularPricingPriority;
83 }
84 }
85
86 public static function updateFromPOST( $ruleId ) {
87 $tieredPricingPriority = isset( $_POST['_tpt_settings_tiered_pricing_priority_type'] ) ? sanitize_text_field( $_POST['_tpt_settings_tiered_pricing_priority_type'] ) : 'prefer-product';
88 $allowTieredPricingMixAndMatch = isset( $_POST['_tpt_settings_tiered_pricing_allow_mix_and_match'] );
89
90 $regularPricingPriority = isset( $_POST['_tpt_settings_regular_pricing_priority_type'] ) ? sanitize_text_field( $_POST['_tpt_settings_regular_pricing_priority_type'] ) : 'prefer-role-based-product';
91 $quantityLimitsPriority = isset( $_POST['_tpt_settings_quantity_limits_priority_type'] ) ? sanitize_text_field( $_POST['_tpt_settings_quantity_limits_priority_type'] ) : 'prefer-product';
92 $priorityType = isset( $_POST['_tpt_settings_priority_type'] ) ? sanitize_text_field( $_POST['_tpt_settings_priority_type'] ) : 'default';
93
94
95 update_post_meta( $ruleId, '_tpt_settings_tiered_pricing_priority_type', $tieredPricingPriority );
96 update_post_meta( $ruleId, '_tpt_settings_tiered_pricing_allow_mix_and_match',
97 $allowTieredPricingMixAndMatch ? 'yes' : 'no' );
98 update_post_meta( $ruleId, '_tpt_settings_regular_pricing_priority_type', $regularPricingPriority );
99 update_post_meta( $ruleId, '_tpt_settings_quantity_limits_priority_type', $quantityLimitsPriority );
100
101 update_post_meta( $ruleId, '_tpt_settings_priority_type', $priorityType );
102 }
103
104 }
105