PluginProbe
Tiered Pricing Table for WooCommerce / 2.2.2
Tiered Pricing Table for WooCommerce v2.2.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 2.3.4 All 90 releases
← All changes | src/Settings/Settings.php +337 -357 trunk2.2.2 View file →
@@ -1,25 +1,8 @@
1 -<?php
1 +<?php namespace TierPricingTable\Settings;
2 2
3 -namespace TierPricingTable\Settings;
3 +use Premmerce\SDK\V2\FileManager\FileManager;
4 4
5 -use TierPricingTable\Core\ServiceContainerTrait;
6 -use TierPricingTable\Settings\CustomOptions\TPTDisplayType;
7 -use TierPricingTable\Settings\CustomOptions\TPTLinkButton;
8 -use TierPricingTable\Settings\CustomOptions\TPTTableColumnsField;
9 -use TierPricingTable\Settings\CustomOptions\TPTQuantityMeasurementField;
10 -use TierPricingTable\Settings\CustomOptions\TPTFeatureFlagOption;
11 -use TierPricingTable\Settings\CustomOptions\TPTIntegrationOption;
12 -use TierPricingTable\Settings\CustomOptions\TPTSwitchOption;
13 -use TierPricingTable\Settings\CustomOptions\TPTTextTemplate;
14 -use TierPricingTable\Settings\Sections\Advanced\AdvancedSection;
15 -use TierPricingTable\Settings\Sections\CalculationLogic\CalculationLogic;
16 -use TierPricingTable\Settings\Sections\GeneralSection\GeneralSection;
17 -use TierPricingTable\Settings\Sections\Integrations\IntegrationSection;
18 -use TierPricingTable\Settings\Sections\Multicurrency\MulticurrencySection;
19 -use TierPricingTable\Settings\Sections\ProductAddons\ProductAddonsSection;
20 -use TierPricingTable\Settings\Sections\SectionAbstract;
21 -use TierPricingTable\TierPricingTablePlugin;
22 5 /**
23 6 * Class Settings
24 7 *
25 8 * @package TierPricingTable\Settings
@@ -24,363 +7,360 @@
24 7 *
25 8 * @package TierPricingTable\Settings
26 9 */
27 10 class Settings {
28 - use ServiceContainerTrait;
29 - const SETTINGS_PREFIX = 'tier_pricing_table_';
30 11
31 - const SETTINGS_PAGE = 'tiered_pricing_table_settings';
12 + const SETTINGS_PREFIX = 'tier_pricing_table_';
32 13
33 - const DEFAULT_SECTION = 'general';
14 + const SETTINGS_PAGE = 'tiered_pricing_table_settings';
34 15
35 - /**
36 - * Settings
37 - *
38 - * @var array
39 - */
40 - private $settings = array();
16 + /**
17 + * @var FileManager
18 + */
19 + private $fileManager;
41 20
42 - /**
43 - * Settings sections
44 - *
45 - * @var SectionAbstract[]
46 - */
47 - protected $sections = array();
21 + /**
22 + * @var array
23 + */
24 + private $settings;
48 25
49 - /**
50 - * Settings constructor.
51 - */
52 - public function __construct() {
53 - $this->initCustomOptions();
54 - $this->hooks();
55 - if ( !tpt_fs()->can_use_premium_code() ) {
56 - new PremiumSettingsManager();
57 - }
58 - if ( !tpt_fs()->can_use_premium_code() ) {
59 - $template = 'upgrade-banner.php';
60 - add_action( 'woocommerce_settings_' . self::SETTINGS_PAGE, function () use($template) {
61 - $this->getContainer()->getFileManager()->includeTemplate( 'admin/banners/' . $template, [
62 - 'upgradeUrl' => tpt_fs_activation_url(),
63 - 'contactUsUrl' => TierPricingTablePlugin::getContactUsURL(),
64 - 'documentationUrl' => TierPricingTablePlugin::getDocumentationURL(),
65 - ] );
66 - } );
67 - }
68 - if ( tpt_fs()->can_use_premium_code() && !tpt_fs()->is_premium() ) {
69 - add_action( 'woocommerce_settings_' . self::SETTINGS_PAGE, function () {
70 - $this->getContainer()->getFileManager()->includeTemplate( 'admin/banners/free-version-used-premium-available.php' );
71 - } );
72 - }
73 - add_action( 'admin_enqueue_scripts', function () {
74 - $assetName = self::SETTINGS_PAGE . '_script';
75 - wp_register_script(
76 - $assetName,
77 - $this->getContainer()->getFileManager()->locateJSAsset( 'admin/settings' ),
78 - array('jquery'),
79 - TierPricingTablePlugin::VERSION,
80 - true
81 - );
82 - wp_enqueue_script( $assetName );
83 - } );
84 - }
26 + /**
27 + * Settings constructor.
28 + *
29 + * @param FileManager $fileManager
30 + */
31 + public function __construct( FileManager $fileManager ) {
32 + $this->fileManager = $fileManager;
85 33
86 - protected function initCustomOptions() {
87 - $this->getContainer()->add( 'settings.tpt_switch_option', new TPTSwitchOption() );
88 - $this->getContainer()->add( 'settings.tpt_integration_option', new TPTIntegrationOption() );
89 - $this->getContainer()->add( 'settings.tpt_feature_flag_option', new TPTFeatureFlagOption() );
90 - $this->getContainer()->add( 'settings.tpt_text_template', new TPTTextTemplate() );
91 - $this->getContainer()->add( 'settings.tpt_display_type', new TPTDisplayType() );
92 - $this->getContainer()->add( 'settings.tpt_link_button', new TPTLinkButton() );
93 - $this->getContainer()->add( 'settings.tpt_quantity_measurement', new TPTQuantityMeasurementField() );
94 - $this->getContainer()->add( 'settings.tpt_multiple_fields', new TPTTableColumnsField() );
95 - }
34 + $this->hooks();
35 + }
96 36
97 - protected function initSections() {
98 - }
37 + /**
38 + * Handle updating settings
39 + */
40 + public function updateSettings() {
41 + woocommerce_update_options( $this->settings );
42 + }
99 43
100 - /**
101 - * Handle updating settings
102 - */
103 - public function updateSettings() {
104 - woocommerce_update_options( $this->settings );
105 - $this->getContainer()->getCache()->purge();
106 - }
44 + /**
45 + * Init all settings
46 + */
47 + public function initSettings() {
48 + $this->settings = array(
49 + [
50 + 'title' => __( 'Tiered price table settings', 'tier-pricing-table' ),
51 + 'desc' => __( 'This controls how tiered pricing table will be displayed in your store',
52 + 'tier-pricing-table' ),
53 + 'id' => self::SETTINGS_PREFIX . 'options',
54 + 'type' => 'title',
55 + ],
56 + [
57 + 'title' => __( 'Show tiered price table', 'tier-pricing-table' ),
58 + 'id' => self::SETTINGS_PREFIX . 'display',
59 + 'type' => 'checkbox',
60 + 'default' => 'yes',
61 + 'desc' => __( 'Display a table on frontend? Prices will change even if it is off',
62 + 'tier-pricing-table' ),
63 + 'desc_tip' => true,
64 + ],
65 + [
66 + 'title' => __( 'Display', 'tier-pricing-table' ),
67 + 'id' => self::SETTINGS_PREFIX . 'display_type',
68 + 'type' => 'select',
69 + 'options' => [
70 + 'tooltip' => __( 'Tooltip', 'tier-pricing-table' ),
71 + 'table' => __( 'Table', 'tier-pricing-table' ),
72 + ],
73 + 'desc' => __( 'Type of displaying', 'tier-pricing-table' ),
74 + 'desc_tip' => true,
75 + 'default' => 'table',
76 + ],
77 + [
78 + 'title' => __( 'Tooltip icon color', 'tier-pricing-table' ),
79 + 'id' => self::SETTINGS_PREFIX . 'tooltip_color',
80 + 'type' => 'color',
81 + 'default' => '#cc99c2',
82 + 'desc' => __( 'Color of icon', 'tier-pricing-table' ),
83 + 'desc_tip' => true,
84 + ],
85 + [
86 + 'title' => __( 'Tooltip icon size (px)', 'tier-pricing-table' ),
87 + 'id' => self::SETTINGS_PREFIX . 'tooltip_size',
88 + 'type' => 'number',
89 + 'default' => '15',
90 + 'desc' => __( 'Size of icon', 'tier-pricing-table' ),
91 + 'desc_tip' => true,
92 + ],
93 + [
94 + 'title' => __( 'Tooltip border', 'tier-pricing-table' ),
95 + 'id' => self::SETTINGS_PREFIX . 'tooltip_border',
96 + 'type' => 'checkbox',
97 + 'default' => 'yes',
98 + 'desc' => __( 'Enable tooltip border', 'tier-pricing-table' ),
99 + ],
100 + [
101 + 'title' => __( 'Table title', 'tier-pricing-table' ),
102 + 'id' => self::SETTINGS_PREFIX . 'table_title',
103 + 'type' => 'text',
104 + 'default' => '',
105 + 'desc' => __( 'The name is being displayed above the table', 'tier-pricing-table' ),
106 + 'desc_tip' => true,
107 + ],
108 + [
109 + 'title' => __( 'Table position', 'tier-pricing-table' ),
110 + 'id' => self::SETTINGS_PREFIX . 'position_hook',
111 + 'type' => 'select',
112 + 'options' => [
113 + 'woocommerce_before_add_to_cart_button' => __( 'Above buy button', 'tier-pricing-table' ),
114 + 'woocommerce_after_add_to_cart_button' => __( 'Below buy button', 'tier-pricing-table' ),
115 + 'woocommerce_before_add_to_cart_form' => __( 'Above add to cart form', 'tier-pricing-table' ),
116 + 'woocommerce_after_add_to_cart_form' => __( 'Below add to cart form', 'tier-pricing-table' ),
117 + 'woocommerce_single_product_summary' => __( 'Above product title', 'tier-pricing-table' ),
118 + 'woocommerce_before_single_product_summary' => __( 'Before product summary', 'tier-pricing-table' ),
119 + 'woocommerce_after_single_product_summary' => __( 'After product summary', 'tier-pricing-table' ),
120 + ],
121 + 'desc' => __( 'Where to display the table', 'tier-pricing-table' ),
122 + 'desc_tip' => true,
123 + ],
124 + [
125 + 'title' => __( 'Active price background color', 'tier-pricing-table' ),
126 + 'id' => self::SETTINGS_PREFIX . 'selected_quantity_color',
127 + 'type' => 'color',
128 + 'css' => 'width:6em;',
129 + 'default' => '#cc99c2',
130 + 'desc' => __( 'Active tiered price background color', 'tier-pricing-table' ),
131 + 'desc_tip' => true,
132 + ],
133 + [
134 + 'title' => __( 'Quantity text', 'tier-pricing-table' ),
135 + 'id' => self::SETTINGS_PREFIX . 'head_quantity_text',
136 + 'type' => 'text',
137 + 'default' => __( 'Quantity', 'tier-pricing-table' ),
138 + 'desc' => __( 'Name of quantity column. Leave Price text and Quantity text blank to do not show table head',
139 + 'tier-pricing-table' ),
140 + 'desc_tip' => true,
141 + ],
142 + [
143 + 'title' => __( 'Price text', 'tier-pricing-table' ),
144 + 'id' => self::SETTINGS_PREFIX . 'head_price_text',
145 + 'type' => 'text',
146 + 'default' => __( 'Price', 'tier-pricing-table' ),
147 + 'desc' => __( 'Name of price column. Leave Price text and Quantity text blank to do not show table head',
148 + 'tier-pricing-table' ),
149 + 'desc_tip' => true,
150 + ],
151 + [
152 + 'title' => __( 'CSS class', 'tier-pricing-table' ),
153 + 'id' => self::SETTINGS_PREFIX . 'table_css_class',
154 + 'type' => 'text',
155 + 'default' => '',
156 + 'desc' => __( 'Add your own CSS styles for the class. The class would be added to the table.',
157 + 'tier-pricing-table' ),
158 + 'desc_tip' => true,
159 + ],
160 + [
161 + 'type' => 'sectionend',
162 + 'id' => self::SETTINGS_PREFIX . 'options'
163 + ],
107 164
108 - /**
109 - * Order the settings sections deterministically: configuration first, then display, features,
110 - * feature toggles, third-party sections, and maintenance last. Without this the tab order is an
111 - * accident of hook registration, because every addon splices its section in relative to another.
112 - *
113 - * Sections with an unknown slug (third-party) keep their relative order and land before Tools.
114 - *
115 - * @param array $sections
116 - *
117 - * @return array
118 - */
119 - protected function sortSections( array $sections ) : array {
120 - $order = (array) apply_filters( 'tiered_pricing_table/settings/sections_order', array(
121 - 'general' => 10,
122 - 'calculation_logic' => 20,
123 - 'shop-loop-display' => 30,
124 - 'tier-labels' => 40,
125 - 'request-a-quote' => 50,
126 - 'advanced' => 60,
127 - 'integrations' => 70,
128 - 'multicurrency' => 80,
129 - 'product-addons' => 90,
130 - 'tools' => 110,
131 - ) );
132 - // Stable sort: usort() is only guaranteed stable on PHP 8+, so tie-break on the original index.
133 - $indexed = array();
134 - foreach ( array_values( $sections ) as $index => $section ) {
135 - $indexed[] = array($order[$section->getSlug()] ?? 100, $index, $section);
136 - }
137 - usort( $indexed, function ( $a, $b ) {
138 - return ( $a[0] <=> $b[0] ?: $a[1] <=> $b[1] );
139 - } );
140 - return array_column( $indexed, 2 );
141 - }
165 + // Premium Here
166 + [
167 + 'title' => __( 'Advanced settings', 'tier-pricing-table' ),
168 + 'id' => self::SETTINGS_PREFIX . 'premium_options',
169 + 'type' => 'title',
170 + 'custom_attributes' => [ 'data-tiered-pricing-premium-setting' => true ]
171 + ],
172 + [
173 + 'title' => __( 'Show Tiered Price in Cart as the Discount', 'tier-pricing-table' ),
174 + 'id' => self::SETTINGS_PREFIX . 'show_discount_in_cart',
175 + 'desc' => __( 'Example:', 'tier-pricing-table' ) . ' <del>10$</del> 8$',
176 + 'type' => 'checkbox',
177 + 'default' => 'yes',
178 + 'desc_tip' => true,
179 + 'custom_attributes' => [ 'data-tiered-pricing-premium-setting' => 'yes' ]
180 + ],
181 + [
182 + 'title' => __( 'Enable price formatting on the catalog page, widgets, etc',
183 + 'tier-pricing-table' ),
184 + 'id' => self::SETTINGS_PREFIX . 'tiered_price_at_catalog',
185 + 'type' => 'checkbox',
186 + 'default' => 'yes',
187 + 'desc' => __( 'Change price formatting on the whole site (show range or minimal price)',
188 + 'tier-pricing-table' ),
189 + 'desc_tip' => true,
190 + 'custom_attributes' => [ 'data-tiered-pricing-premium-setting' => true ]
191 + ],
192 + [
193 + 'title' => __( 'Enable price formatting on product page ', 'tier-pricing-table' ),
194 + 'id' => self::SETTINGS_PREFIX . 'tiered_price_at_product_page',
195 + 'type' => 'checkbox',
196 + 'default' => 'no',
197 + 'desc' => __( 'Change price for product at product page (show range or minimal price)',
198 + 'tier-pricing-table' ),
199 + 'desc_tip' => true,
200 + 'custom_attributes' => [ 'data-tiered-pricing-premium-setting' => true ]
201 + ],
202 + [
203 + 'title' => __( 'Enable catalog, widget price formatting for variable products',
204 + 'tier-pricing-table' ),
205 + 'id' => self::SETTINGS_PREFIX . 'tiered_price_at_catalog_for_variable',
206 + 'type' => 'checkbox',
207 + 'default' => 'yes',
208 + 'desc' => __( 'Show tiered price at the catalog for variable products. Uses the lowest and the highest prices from all variations',
209 + 'tier-pricing-table' ),
210 + 'desc_tip' => true,
211 + 'custom_attributes' => [ 'data-tiered-pricing-premium-setting' => true ]
212 + ],
213 + [
214 + 'title' => __( 'Display Tiered Price as', 'tier-pricing-table' ),
215 + 'id' => self::SETTINGS_PREFIX . 'tiered_price_at_catalog_type',
216 + 'type' => 'select',
217 + 'options' => [
218 + 'range' => __( 'Range (from lowest to highest)', 'tier-pricing-table' ),
219 + 'lowest' => __( 'Lowest price', 'tier-pricing-table' ),
220 + ],
221 + 'desc' => __( 'How to Display Tiered Price at The Catalog', 'tier-pricing-table' ),
222 + 'desc_tip' => true,
223 + 'custom_attributes' => [ 'data-tiered-pricing-premium-setting' => true ]
224 + ],
225 + [
226 + 'title' => __( 'Lowest price prefix', 'tier-pricing-table' ),
227 + 'id' => self::SETTINGS_PREFIX . 'lowest_prefix',
228 + 'type' => 'text',
229 + 'default' => __( 'From', 'tier-pricing-table' ),
230 + 'desc' => __( 'Prefix Before Lowest Tiered Product Price at the Catalog. Example: <b>From 10$</b>',
231 + 'tier-pricing-table' ),
232 + 'desc_tip' => true,
233 + 'custom_attributes' => [ 'data-tiered-pricing-premium-setting' => true ]
234 + ],
235 + [
236 + 'title' => __( 'Show discount column for percentage table', 'tier-pricing-table' ),
237 + 'id' => self::SETTINGS_PREFIX . 'show_discount_column',
238 + 'type' => 'checkbox',
239 + 'default' => 'yes',
240 + 'custom_attributes' => [ 'data-tiered-pricing-premium-setting' => true ]
241 + ],
242 + [
243 + 'title' => __( 'Discount column text', 'tier-pricing-table' ),
244 + 'id' => self::SETTINGS_PREFIX . 'head_discount_text',
245 + 'type' => 'text',
246 + 'default' => __( 'Discount (%)', 'tier-pricing-table' ),
247 + 'desc' => __( 'Name of discount column', 'tier-pricing-table' ),
248 + 'desc_tip' => true,
249 + 'custom_attributes' => [ 'data-tiered-pricing-premium-setting' => true ]
250 + ],
251 + [
252 + 'title' => __( 'Set tiered price on click', 'tier-pricing-table' ),
253 + 'id' => self::SETTINGS_PREFIX . 'clickable_table_rows',
254 + 'type' => 'checkbox',
255 + 'default' => 'no',
256 + 'desc' => __( 'Change product quantity on click at table pricing row',
257 + 'tier-pricing-table' ),
258 + 'custom_attributes' => [ 'data-tiered-pricing-premium-setting' => true ]
259 + ],
260 + [
261 + 'title' => __( 'Show total price', 'tier-pricing-table' ),
262 + 'id' => self::SETTINGS_PREFIX . 'show_total_price',
263 + 'type' => 'checkbox',
264 + 'default' => 'no',
265 + 'desc' => __( 'Calculate and show total price at product page',
266 + 'tier-pricing-table' ),
267 + 'custom_attributes' => [ 'data-tiered-pricing-premium-setting' => true ]
268 + ],
269 + [
270 + 'type' => 'sectionend',
271 + 'id' => self::SETTINGS_PREFIX . 'premium_options'
272 + ],
273 + );
274 + }
142 275
143 - /**
144 - * Init all settings
145 - */
146 - public function initSettings() {
147 - $this->sections = apply_filters( 'tiered_pricing_table/settings/sections', array(
148 - new GeneralSection(),
149 - new CalculationLogic(),
150 - new AdvancedSection(),
151 - new MulticurrencySection(),
152 - new ProductAddonsSection(),
153 - new IntegrationSection()
154 - ) );
155 - $this->sections = $this->sortSections( $this->sections );
156 - foreach ( $this->sections as $section ) {
157 - if ( $section->isActive() ) {
158 - $this->settings = $section->getSettings();
159 - break;
160 - }
161 - }
162 - }
276 + /**
277 + * Register hooks
278 + */
279 + public function hooks() {
280 + add_action( 'init', [ $this, 'initSettings' ] );
163 281
164 - /**
165 - * Register hooks
166 - */
167 - public function hooks() {
168 - add_action( 'init', array($this, 'initSettings') );
169 - add_filter( 'woocommerce_settings_tabs_' . self::SETTINGS_PAGE, array($this, 'addTieredPricingTableSettings') );
170 - add_filter( 'woocommerce_settings_tabs_array', array($this, 'addSettingsTab'), 50 );
171 - add_action( 'woocommerce_update_options_' . self::SETTINGS_PAGE, array($this, 'updateSettings') );
172 - add_action( 'woocommerce_settings_' . self::SETTINGS_PAGE, array($this, 'renderSections'), 99 );
173 - }
282 + add_filter( 'woocommerce_settings_tabs_' . self::SETTINGS_PAGE, [ $this, 'addTieredPricingTableSettings' ] );
283 + add_filter( 'woocommerce_settings_tabs_array', [ $this, 'addSettingsTab' ], 50 );
284 + add_action( 'woocommerce_update_options_' . self::SETTINGS_PAGE, [ $this, 'updateSettings' ] );
285 + }
174 286
175 - public function renderSections() {
176 - // Opening a section clears its "unread" indicator (store-wide)
177 - foreach ( $this->sections as $section ) {
178 - if ( $section->isActive() ) {
179 - $section->markBadgeSeen();
180 - }
181 - }
182 - ?>
183 - <style>
184 - h2 {
185 - margin-top: 2em;
186 - font-size: 1.45em;
187 - }
188 - </style>
287 + /**
288 + * Add own settings tab
289 + *
290 + * @param array $settings_tabs
291 + *
292 + * @return mixed
293 + */
294 + public static function addSettingsTab( $settings_tabs ) {
189 295
190 - <ul class="subsubsub" style="font-size: 1.1em; margin-top: 3px">
191 - <?php
192 - $sectionsCount = count( $this->sections );
193 - ?>
194 - <?php
195 - foreach ( $this->sections as $index => $section ) {
196 - ?>
197 - <li>
198 - <?php
199 - if ( !$section->isActive() ) {
200 - ?>
201 - <a href="<?php
202 - echo esc_attr( $section->getURL() );
203 - ?>">
204 - <?php
205 - if ( $section->isIntegration() ) {
206 - ?>
207 - <small style="width: 10px; height: 10px; display: inline-block; margin-right: 10px;">
208 - <span class="dashicons dashicons-admin-plugins"></span>
209 - </small>
210 - <b><?php
211 - echo esc_html( $section->getName() );
212 - ?></b>
213 - <?php
214 - } else {
215 - ?>
216 - <?php
217 - echo esc_html( $section->getName() );
218 - ?>
219 - <?php
220 - if ( $section->isBadgeUnseen() ) {
221 - ?>
222 - <span class="tpt-unread-badge" aria-hidden="true">1</span><span class="screen-reader-text"><?php
223 - esc_html_e( 'New', 'tier-pricing-table' );
224 - ?></span>
225 - <?php
226 - }
227 - ?>
228 - <?php
229 - }
230 - ?>
296 + $settings_tabs[ self::SETTINGS_PAGE ] = __( 'Tiered Pricing', 'tier-pricing-table' );
231 297
232 - </a>
233 - <?php
234 - } else {
235 - ?>
298 + return $settings_tabs;
299 + }
236 300
237 - <?php
238 - if ( $section->getSectionCSS() ) {
239 - ?>
240 - <style>
241 - <?php
242 - echo esc_html( $section->getSectionCSS() );
243 - ?>
244 - </style>
245 - <?php
246 - }
247 - ?>
301 + /**
302 + * Add settings to WooCommerce
303 + */
304 + public function addTieredPricingTableSettings() {
248 305
249 - <a class="current" href="#">
250 - <?php
251 - echo esc_html( $section->getName() );
252 - ?>
253 - </a>
254 - <?php
255 - }
256 - ?>
257 - <?php
258 - if ( $index < $sectionsCount - 1 ) {
259 - ?>
260 - |
261 - <?php
262 - }
263 - ?>
264 - </li>
265 - <?php
266 - }
267 - ?>
268 - </ul>
269 - <br class="clear">
270 - <?php
271 - }
306 + wp_enqueue_script( 'quantity-table-settings-js', $this->fileManager->locateAsset( 'admin/settings.js' ) );
272 307
273 - /**
274 - * Add own settings tab
275 - *
276 - * @param $settingsTabs
277 - *
278 - * @return array
279 - */
280 - public static function addSettingsTab( $settingsTabs ) : array {
281 - $settingsTabs = ( is_array( $settingsTabs ) ? $settingsTabs : array() );
282 - $settingsTabs[self::SETTINGS_PAGE] = __( 'Tiered Pricing', 'tier-pricing-table' );
283 - return $settingsTabs;
284 - }
308 + return woocommerce_admin_fields( $this->settings );
309 + }
285 310
286 - /**
287 - * Add settings to WooCommerce
288 - */
289 - public function addTieredPricingTableSettings() {
290 - woocommerce_admin_fields( $this->settings );
291 - }
311 + /**
312 + * Get all settings
313 + *
314 + * @return array
315 + */
316 + public function getAll() {
317 + return [
318 + 'display' => $this->get( 'display', 'yes' ),
319 + 'position_hook' => $this->get( 'position_hook',
320 + 'woocommerce_after_add_to_cart_button' ),
321 + 'head_quantity_text' => $this->get( 'head_quantity_text',
322 + __( 'Quantity', 'tier-pricing-table' ) ),
323 + 'head_price_text' => $this->get( 'head_price_text',
324 + __( 'Price', 'tier-pricing-table' ) ),
325 + 'display_type' => $this->get( 'display_type', 'table' ),
326 + 'selected_quantity_color' => $this->get( 'selected_quantity_color', '#cc99c2' ),
327 + 'table_title' => $this->get( 'table_title', '' ),
328 + 'table_css_class' => $this->get( 'table_css_class', '#fff' ),
329 + 'tooltip_size' => $this->get( 'tooltip_size', 15 ),
330 + 'tooltip_border' => $this->get( 'tooltip_border', 'yes' ),
292 331
293 - /**
294 - * Get setting by name
295 - *
296 - * @param string $optionName
297 - * @param mixed $default
298 - *
299 - * @return mixed
300 - */
301 - public function get( string $optionName, $default = null ) {
302 - return get_option( self::SETTINGS_PREFIX . $optionName, $default );
303 - }
332 + /* Premium */
333 + 'show_discount_in_cart' => $this->get( 'show_discount_in_cart', 'yes' ),
334 + 'tiered_price_at_catalog' => $this->get( 'tiered_price_at_catalog', 'yes' ),
335 + 'tiered_price_at_catalog_for_variable' => $this->get( 'tiered_price_at_catalog_for_variable', 'yes' ),
336 + 'tiered_price_at_catalog_type' => $this->get( 'tiered_price_at_catalog_type', 'yes' ),
337 + 'lowest_prefix' => $this->get( 'lowest_prefix', 'yes' ),
338 + 'show_discount_column' => $this->get( 'show_discount_column', 'yes' ),
339 + 'clickable_table_rows' => $this->get( 'clickable_table_rows', 'no' ),
340 + 'show_total_price' => $this->get( 'show_total_price', 'no' ),
341 + 'head_discount_text' => $this->get( 'head_discount_text',
342 + __( 'Discount (%)', 'tier-pricing-table' ) ),
343 + ];
344 + }
304 345
305 - public static function deleteOptions() {
306 - GeneralSection::deleteOptions();
307 - AdvancedSection::deleteOptions();
308 - IntegrationSection::deleteOptions();
309 - }
346 + /**
347 + * Get setting by name
348 + *
349 + * @param string $option_name
350 + * @param mixed $default
351 + *
352 + * @return mixed
353 + */
354 + public function get( $option_name, $default = null ) {
355 + return get_option( self::SETTINGS_PREFIX . $option_name, $default );
356 + }
310 357
311 - /**
312 - * Get url to settings page
313 - *
314 - * @return string
315 - */
316 - public function getLink() : string {
317 - return admin_url( 'admin.php?page=wc-settings&tab=tiered_pricing_table_settings' );
318 - }
319 -
320 - public static function hex2rgba( $color, $opacity = false ) : string {
321 - $default = 'rgb(0,0,0)';
322 - if ( empty( $color ) ) {
323 - return $default;
324 - }
325 - if ( '#' === $color[0] ) {
326 - $color = substr( $color, 1 );
327 - }
328 - if ( strlen( $color ) == 6 ) {
329 - $hex = array($color[0] . $color[1], $color[2] . $color[3], $color[4] . $color[5]);
330 - } elseif ( strlen( $color ) == 3 ) {
331 - $hex = array($color[0] . $color[0], $color[1] . $color[1], $color[2] . $color[2]);
332 - } else {
333 - return $default;
334 - }
335 - $rgb = array_map( 'hexdec', $hex );
336 - if ( $opacity ) {
337 - if ( abs( $opacity ) > 1 ) {
338 - $opacity = 1.0;
339 - }
340 - $output = 'rgba(' . implode( ',', $rgb ) . ',' . $opacity . ')';
341 - } else {
342 - $output = 'rgb(' . implode( ',', $rgb ) . ')';
343 - }
344 - return $output;
345 - }
346 -
347 - public static function shadeHexWithOpacity( $hex, $opacity, $bgHex = '#FFFFFF' ) {
348 - // Normalize and parse the foreground hex
349 - $hex = ltrim( $hex, '#' );
350 - if ( strlen( $hex ) === 3 ) {
351 - $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2];
352 - }
353 - if ( strlen( $hex ) !== 6 ) {
354 - return false;
355 - }
356 - // Normalize and parse the background hex
357 - $bgHex = ltrim( $bgHex, '#' );
358 - if ( strlen( $bgHex ) === 3 ) {
359 - $bgHex = $bgHex[0] . $bgHex[0] . $bgHex[1] . $bgHex[1] . $bgHex[2] . $bgHex[2];
360 - }
361 - if ( strlen( $bgHex ) !== 6 ) {
362 - return false;
363 - }
364 - // Clamp opacity
365 - $opacity = max( 0, min( 1, $opacity ) );
366 - // Extract RGB
367 - $r = hexdec( substr( $hex, 0, 2 ) );
368 - $g = hexdec( substr( $hex, 2, 2 ) );
369 - $b = hexdec( substr( $hex, 4, 2 ) );
370 - $bgR = hexdec( substr( $bgHex, 0, 2 ) );
371 - $bgG = hexdec( substr( $bgHex, 2, 2 ) );
372 - $bgB = hexdec( substr( $bgHex, 4, 2 ) );
373 - // Blend with background using alpha compositing
374 - $newR = round( $opacity * $r + (1 - $opacity) * $bgR );
375 - $newG = round( $opacity * $g + (1 - $opacity) * $bgG );
376 - $newB = round( $opacity * $b + (1 - $opacity) * $bgB );
377 - // Return final hex
378 - return sprintf(
379 - '#%02X%02X%02X',
380 - $newR,
381 - $newG,
382 - $newB
383 - );
384 - }
385 -
386 -}
358 + /**
359 + * Get url to settings page
360 + *
361 + * @return string
362 + */
363 + public function getLink() {
364 + return admin_url( 'admin.php?page=wc-settings&tab=tiered_pricing_table_settings' );
365 + }
366 +}