| 1 |
<?php namespace TierPricingTable\Settings\Sections\CalculationLogic; |
| 2 |
|
| 3 |
use TierPricingTable\Settings\CustomOptions\TPTSwitchOption; |
| 4 |
use TierPricingTable\Settings\Sections\SectionAbstract; |
| 5 |
use TierPricingTable\Settings\Settings; |
| 6 |
|
| 7 |
class CalculationLogic extends SectionAbstract { |
| 8 |
|
| 9 |
public function getSettings() { |
| 10 |
$settings = apply_filters( 'tiered_pricing_table/settings/calculation_logic', $this->getMainSettings() ); |
| 11 |
|
| 12 |
return array_merge( $settings, $this->getGlobalPricingRulesOptions() ); |
| 13 |
} |
| 14 |
|
| 15 |
public function getMainSettings(): array { |
| 16 |
return array( |
| 17 |
array( |
| 18 |
'title' => __( 'Variable products logic', 'tier-pricing-table' ), |
| 19 |
'desc' => __( 'Control how tiered pricing handles variable products.', 'tier-pricing-table' ), |
| 20 |
'id' => Settings::SETTINGS_PREFIX . 'variable_products_logic', |
| 21 |
'type' => 'title', |
| 22 |
), |
| 23 |
array( |
| 24 |
'title' => __( 'Combine variations for quantity calculation', |
| 25 |
'tier-pricing-table' ), |
| 26 |
'id' => Settings::SETTINGS_PREFIX . 'summarize_variations', |
| 27 |
'type' => TPTSwitchOption::FIELD_TYPE, |
| 28 |
'default' => 'no', |
| 29 |
'extended_description' => __( 'Treat all variations of a variable product as the same item when calculating the total cart quantity for tiered pricing rules.', |
| 30 |
'tier-pricing-table' ), |
| 31 |
'desc_tip' => true, |
| 32 |
), |
| 33 |
array( |
| 34 |
'title' => __( 'Combine variations for minimum quantity', 'tier-pricing-table' ), |
| 35 |
'id' => Settings::SETTINGS_PREFIX . 'mix_and_match_minimum', |
| 36 |
'type' => TPTSwitchOption::FIELD_TYPE, |
| 37 |
'default' => 'no', |
| 38 |
'extended_description' => __( 'Determine whether the minimum quantity requirement applies to each variation separately, or to the combined total of all variations in the cart.', 'tier-pricing-table' ), |
| 39 |
'desc_tip' => true, |
| 40 |
), |
| 41 |
array( |
| 42 |
'type' => 'sectionend', |
| 43 |
'id' => Settings::SETTINGS_PREFIX . 'variable_products_logic', |
| 44 |
), |
| 45 |
array( |
| 46 |
'title' => __( 'General calculations', 'tier-pricing-table' ), |
| 47 |
'desc' => __( 'Control general calculation behavior for tiered pricing.', 'tier-pricing-table' ), |
| 48 |
'id' => Settings::SETTINGS_PREFIX . 'general_calculations', |
| 49 |
'type' => 'title', |
| 50 |
), |
| 51 |
array( |
| 52 |
'title' => __( 'Calculate percentage discounts from regular price', |
| 53 |
'tier-pricing-table' ), |
| 54 |
'id' => Settings::SETTINGS_PREFIX . 'calculate_discount_based_on_regular_price', |
| 55 |
'type' => TPTSwitchOption::FIELD_TYPE, |
| 56 |
'extended_description' => $this->getCalculateDiscountDescription(), |
| 57 |
'default' => 'no', |
| 58 |
), |
| 59 |
array( |
| 60 |
'title' => __( 'Round calculated prices', 'tier-pricing-table' ), |
| 61 |
'id' => Settings::SETTINGS_PREFIX . 'round_price', |
| 62 |
'type' => TPTSwitchOption::FIELD_TYPE, |
| 63 |
'default' => 'yes', |
| 64 |
'extended_description' => __( 'Round calculated percentage discounts to prevent minor display discrepancies with standard WooCommerce pricing.', |
| 65 |
'tier-pricing-table' ), |
| 66 |
'desc_tip' => true, |
| 67 |
), |
| 68 |
array( |
| 69 |
'type' => 'sectionend', |
| 70 |
'id' => Settings::SETTINGS_PREFIX . 'general_calculations', |
| 71 |
), |
| 72 |
); |
| 73 |
} |
| 74 |
|
| 75 |
public function getCalculateDiscountDescription() { |
| 76 |
ob_start(); |
| 77 |
?> |
| 78 |
<p> |
| 79 |
<?php |
| 80 |
esc_html_e( 'Calculate percentage discounts using the product\'s regular price, ignoring any active sale prices.', |
| 81 |
'tier-pricing-table' ); |
| 82 |
?> |
| 83 |
</p> |
| 84 |
<p> |
| 85 |
<?php |
| 86 |
esc_html_e( 'Example: Regular price is $100.00, sale price is $90.00. Rule: 20% off.', |
| 87 |
'tier-pricing-table' ); |
| 88 |
?> |
| 89 |
<br> |
| 90 |
<?php |
| 91 |
esc_html_e( 'Disabled (Default): Discount applies to the sale price ($90.00 - 20% = $72.00).', |
| 92 |
'tier-pricing-table' ); |
| 93 |
?> |
| 94 |
<br> |
| 95 |
<?php |
| 96 |
esc_html_e( 'Enabled: Discount applies to the regular price ($100.00 - 20% = $80.00).', |
| 97 |
'tier-pricing-table' ); |
| 98 |
?> |
| 99 |
</p> |
| 100 |
<?php |
| 101 |
|
| 102 |
return ob_get_clean(); |
| 103 |
} |
| 104 |
|
| 105 |
public function getSlug(): string { |
| 106 |
return 'calculation_logic'; |
| 107 |
} |
| 108 |
|
| 109 |
public function getName(): string { |
| 110 |
return __( 'Calculations', 'tier-pricing-table' ); |
| 111 |
} |
| 112 |
|
| 113 |
protected function getGlobalPricingRulesOptions(): array { |
| 114 |
return array( |
| 115 |
array( |
| 116 |
'title' => __( 'Global pricing rules', 'tier-pricing-table' ), |
| 117 |
'desc' => __( 'How global pricing rules behave.', 'tier-pricing-table' ), |
| 118 |
'type' => 'title', |
| 119 |
), |
| 120 |
array( |
| 121 |
'title' => __( 'Prioritize global pricing rules', 'tier-pricing-table' ), |
| 122 |
'id' => Settings::SETTINGS_PREFIX . 'override_prices_by_global_rules', |
| 123 |
'extended_description' => __( 'Apply global pricing rules before product-level rules. If disabled, individual product rules take precedence over global rules.', |
| 124 |
'tier-pricing-table' ), |
| 125 |
'type' => TPTSwitchOption::FIELD_TYPE, |
| 126 |
'default' => 'no', |
| 127 |
), |
| 128 |
array( |
| 129 |
'type' => 'sectionend', |
| 130 |
), |
| 131 |
); |
| 132 |
} |
| 133 |
|
| 134 |
} |