PluginProbe
Tiered Pricing Table for WooCommerce / 2.3.4
Tiered Pricing Table for WooCommerce v2.3.4
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 / Settings / Settings.php

Settings.php in Tiered Pricing Table for WooCommerce 2.3.4, at src/Settings/Settings.php

460 lines 18.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php namespace TierPricingTable\Settings;
2
3 use Premmerce\SDK\V2\FileManager\FileManager;
4
5 /**
6 * Class Settings
7 *
8 * @package TierPricingTable\Settings
9 */
10 class Settings {
11
12 const SETTINGS_PREFIX = 'tier_pricing_table_';
13
14 const SETTINGS_PAGE = 'tiered_pricing_table_settings';
15
16 /**
17 * @var FileManager
18 */
19 private $fileManager;
20
21 /**
22 * @var array
23 */
24 private $settings;
25
26 /**
27 * Settings constructor.
28 *
29 * @param FileManager $fileManager
30 */
31 public function __construct( FileManager $fileManager ) {
32 $this->fileManager = $fileManager;
33
34 $this->hooks();
35 }
36
37 /**
38 * Handle updating settings
39 */
40 public function updateSettings() {
41 woocommerce_update_options( $this->settings );
42 }
43
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 [
79 'title' => __( 'Tooltip icon color', 'tier-pricing-table' ),
80 'id' => self::SETTINGS_PREFIX . 'tooltip_color',
81 'type' => 'color',
82 'default' => '#cc99c2',
83 'desc' => __( 'Color of icon', 'tier-pricing-table' ),
84 'desc_tip' => true,
85 ],
86 [
87 'title' => __( 'Tooltip icon size (px)', 'tier-pricing-table' ),
88 'id' => self::SETTINGS_PREFIX . 'tooltip_size',
89 'type' => 'number',
90 'default' => '15',
91 'desc' => __( 'Size of icon', 'tier-pricing-table' ),
92 'desc_tip' => true,
93 ],
94 [
95 'title' => __( 'Tooltip border', 'tier-pricing-table' ),
96 'id' => self::SETTINGS_PREFIX . 'tooltip_border',
97 'type' => 'checkbox',
98 'default' => 'yes',
99 'desc' => __( 'Enable tooltip border', 'tier-pricing-table' ),
100 ],
101 [
102 'title' => __( 'Table title', 'tier-pricing-table' ),
103 'id' => self::SETTINGS_PREFIX . 'table_title',
104 'type' => 'text',
105 'default' => '',
106 'desc' => __( 'The name is being displayed above the table', 'tier-pricing-table' ),
107 'desc_tip' => true,
108 ],
109 [
110 'title' => __( 'Table position', 'tier-pricing-table' ),
111 'id' => self::SETTINGS_PREFIX . 'position_hook',
112 'type' => 'select',
113 'options' => [
114 'woocommerce_before_add_to_cart_button' => __( 'Above buy button', 'tier-pricing-table' ),
115 'woocommerce_after_add_to_cart_button' => __( 'Below buy button', 'tier-pricing-table' ),
116 'woocommerce_before_add_to_cart_form' => __( 'Above add to cart form', 'tier-pricing-table' ),
117 'woocommerce_after_add_to_cart_form' => __( 'Below add to cart form', 'tier-pricing-table' ),
118 'woocommerce_single_product_summary' => __( 'Above product title', 'tier-pricing-table' ),
119 'woocommerce_before_single_product_summary' => __( 'Before product summary', 'tier-pricing-table' ),
120 'woocommerce_after_single_product_summary' => __( 'After product summary', 'tier-pricing-table' ),
121 ],
122 'desc' => __( 'Where to display the table', 'tier-pricing-table' ),
123 'desc_tip' => true,
124 ],
125 [
126 'title' => __( 'Active price background color', 'tier-pricing-table' ),
127 'id' => self::SETTINGS_PREFIX . 'selected_quantity_color',
128 'type' => 'color',
129 'css' => 'width:6em;',
130 'default' => '#cc99c2',
131 'desc' => __( 'Active tiered price background color', 'tier-pricing-table' ),
132 'desc_tip' => true,
133 ],
134 [
135 'title' => __( 'Quantity text', 'tier-pricing-table' ),
136 'id' => self::SETTINGS_PREFIX . 'head_quantity_text',
137 'type' => 'text',
138 'default' => __( 'Quantity', 'tier-pricing-table' ),
139 'desc' => __( 'Name of quantity column. Leave Price text and Quantity text blank to do not show table head',
140 'tier-pricing-table' ),
141 'desc_tip' => true,
142 ],
143 [
144 'title' => __( 'Price text', 'tier-pricing-table' ),
145 'id' => self::SETTINGS_PREFIX . 'head_price_text',
146 'type' => 'text',
147 'default' => __( 'Price', 'tier-pricing-table' ),
148 'desc' => __( 'Name of price column. Leave Price text and Quantity text blank to do not show table head',
149 'tier-pricing-table' ),
150 'desc_tip' => true,
151 ],
152 [
153 'title' => __( 'CSS class', 'tier-pricing-table' ),
154 'id' => self::SETTINGS_PREFIX . 'table_css_class',
155 'type' => 'text',
156 'default' => '',
157 'desc' => __( 'Add your own CSS styles for the class. The class would be added to the table.',
158 'tier-pricing-table' ),
159 'desc_tip' => true,
160 ],
161 array(
162 'title' => __( 'Summarize all variation during calculation product variation tiered price',
163 'tier-pricing-table' ),
164 'id' => self::SETTINGS_PREFIX . 'summarize_variations',
165 'type' => 'checkbox',
166 'default' => 'no',
167 'desc' => __( 'Add all variations quantity to calculate actual tiered price for product variation.',
168 'tier-pricing-table' ),
169 'desc_tip' => true,
170 ),
171 [
172 'type' => 'sectionend',
173 'id' => self::SETTINGS_PREFIX . 'options'
174 ],
175
176 // Premium Here
177 [
178 'title' => __( 'Advanced settings', 'tier-pricing-table' ),
179 'id' => self::SETTINGS_PREFIX . 'premium_options',
180 'type' => 'title',
181 'custom_attributes' => [ 'data-tiered-pricing-premium-setting' => true ]
182 ],
183 [
184 'title' => __( 'Show Tiered Price in Cart as the Discount', 'tier-pricing-table' ),
185 'id' => self::SETTINGS_PREFIX . 'show_discount_in_cart',
186 'desc' => __( 'Example:', 'tier-pricing-table' ) . ' <del>10$</del> 8$',
187 'type' => 'checkbox',
188 'default' => 'yes',
189 'desc_tip' => true,
190 'custom_attributes' => [ 'data-tiered-pricing-premium-setting' => 'yes' ]
191 ],
192 [
193 'title' => __( 'Enable price formatting on the catalog page, widgets, etc',
194 'tier-pricing-table' ),
195 'id' => self::SETTINGS_PREFIX . 'tiered_price_at_catalog',
196 'type' => 'checkbox',
197 'default' => 'yes',
198 'desc' => __( 'Change price formatting on the whole site (show range or minimal price)',
199 'tier-pricing-table' ),
200 'desc_tip' => true,
201 'custom_attributes' => [ 'data-tiered-pricing-premium-setting' => true ]
202 ],
203 [
204 'title' => __( 'Enable price formatting on product page ', 'tier-pricing-table' ),
205 'id' => self::SETTINGS_PREFIX . 'tiered_price_at_product_page',
206 'type' => 'checkbox',
207 'default' => 'no',
208 'desc' => __( 'Change price for product at product page (show range or minimal price)',
209 'tier-pricing-table' ),
210 'desc_tip' => true,
211 'custom_attributes' => [ 'data-tiered-pricing-premium-setting' => true ]
212 ],
213 [
214 'title' => __( 'Enable catalog, widget price formatting for variable products',
215 'tier-pricing-table' ),
216 'id' => self::SETTINGS_PREFIX . 'tiered_price_at_catalog_for_variable',
217 'type' => 'checkbox',
218 'default' => 'yes',
219 'desc' => __( 'Show tiered price at the catalog for variable products. Uses the lowest and the highest prices from all variations',
220 'tier-pricing-table' ),
221 'desc_tip' => true,
222 'custom_attributes' => [ 'data-tiered-pricing-premium-setting' => true ]
223 ],
224 [
225 'title' => __( 'Display Tiered Price as', 'tier-pricing-table' ),
226 'id' => self::SETTINGS_PREFIX . 'tiered_price_at_catalog_type',
227 'type' => 'select',
228 'options' => [
229 'range' => __( 'Range (from lowest to highest)', 'tier-pricing-table' ),
230 'lowest' => __( 'Lowest price', 'tier-pricing-table' ),
231 ],
232 'desc' => __( 'How to Display Tiered Price at The Catalog', 'tier-pricing-table' ),
233 'desc_tip' => true,
234 'custom_attributes' => [ 'data-tiered-pricing-premium-setting' => true ]
235 ],
236 [
237 'title' => __( 'Lowest price prefix', 'tier-pricing-table' ),
238 'id' => self::SETTINGS_PREFIX . 'lowest_prefix',
239 'type' => 'text',
240 'default' => __( 'From', 'tier-pricing-table' ),
241 'desc' => __( 'Prefix Before Lowest Tiered Product Price at the Catalog. Example: <b>From 10$</b>',
242 'tier-pricing-table' ),
243 'desc_tip' => true,
244 'custom_attributes' => [ 'data-tiered-pricing-premium-setting' => true ]
245 ],
246 [
247 'title' => __( 'Show discount column for percentage table', 'tier-pricing-table' ),
248 'id' => self::SETTINGS_PREFIX . 'show_discount_column',
249 'type' => 'checkbox',
250 'default' => 'yes',
251 'custom_attributes' => [ 'data-tiered-pricing-premium-setting' => true ]
252 ],
253 [
254 'title' => __( 'Discount column text', 'tier-pricing-table' ),
255 'id' => self::SETTINGS_PREFIX . 'head_discount_text',
256 'type' => 'text',
257 'default' => __( 'Discount (%)', 'tier-pricing-table' ),
258 'desc' => __( 'Name of discount column', 'tier-pricing-table' ),
259 'desc_tip' => true,
260 'custom_attributes' => [ 'data-tiered-pricing-premium-setting' => true ]
261 ],
262 [
263 'title' => __( 'Set tiered price on click', 'tier-pricing-table' ),
264 'id' => self::SETTINGS_PREFIX . 'clickable_table_rows',
265 'type' => 'checkbox',
266 'default' => 'no',
267 'desc' => __( 'Change product quantity on click at table pricing row',
268 'tier-pricing-table' ),
269 'custom_attributes' => [ 'data-tiered-pricing-premium-setting' => true ]
270 ],
271 [
272 'title' => __( 'Show total price', 'tier-pricing-table' ),
273 'id' => self::SETTINGS_PREFIX . 'show_total_price',
274 'type' => 'checkbox',
275 'default' => 'no',
276 'desc' => __( 'Calculate and show total price at product page',
277 'tier-pricing-table' ),
278 'custom_attributes' => [ 'data-tiered-pricing-premium-setting' => true ]
279 ],
280 [
281 'type' => 'sectionend',
282 'id' => self::SETTINGS_PREFIX . 'premium_options'
283 ],
284 // Summary section
285 array(
286 'title' => __( 'Summary block', 'tier-pricing-table' ),
287 'id' => self::SETTINGS_PREFIX . 'summary_section',
288 'type' => 'title',
289 'desc' => __( 'Section controls how summary block at a product page.',
290 'tier-pricing-table' ),
291 'custom_attributes' => [ 'data-tiered-pricing-premium-setting' => true ]
292 ),
293 array(
294 'title' => __( 'Show summary block',
295 'tier-pricing-table' ),
296 'id' => self::SETTINGS_PREFIX . 'display_summary',
297 'type' => 'checkbox',
298 'default' => 'yes',
299 'desc' => __( 'Show summary block at a product page. Display information about actual unit price, product quantity and total',
300 'tier-pricing-table' ),
301 'desc_tip' => true,
302 'custom_attributes' => [ 'data-tiered-pricing-premium-setting' => true ]
303 ),
304 array(
305 'title' => __( 'Summary block title', 'tier-pricing-table' ),
306 'id' => self::SETTINGS_PREFIX . 'summary_title',
307 'type' => 'text',
308 'desc' => __( 'The name is displaying above the summary block.', 'tier-pricing-table' ),
309 'desc_tip' => true,
310 'default' => '',
311 'custom_attributes' => [ 'data-tiered-pricing-premium-setting' => true ]
312 ),
313 array(
314 'title' => __( 'Summary block type', 'tier-pricing-table' ),
315 'id' => self::SETTINGS_PREFIX . 'summary_type',
316 'type' => 'select',
317 'options' => array(
318 'table' => __( 'Table', 'tier-pricing-table' ),
319 'inline' => __( 'Inline', 'tier-pricing-table' ),
320 ),
321 'desc' => __( 'Type of displaying.', 'tier-pricing-table' ),
322 'desc_tip' => true,
323 'default' => 'table',
324 'custom_attributes' => [ 'data-tiered-pricing-premium-setting' => true ]
325 ),
326 array(
327 'title' => __( '"Total" label', 'tier-pricing-table' ),
328 'id' => self::SETTINGS_PREFIX . 'summary_total_label',
329 'type' => 'text',
330 'default' => __( 'Total:', 'tier-pricing-table' ),
331 'desc' => __( 'Label for the "total" line.', 'tier-pricing-table' ),
332 'desc_tip' => true,
333 'custom_attributes' => [ 'data-tiered-pricing-premium-setting' => true ]
334 ),
335 array(
336 'title' => __( '"Each" label', 'tier-pricing-table' ),
337 'id' => self::SETTINGS_PREFIX . 'summary_each_label',
338 'type' => 'text',
339 'default' => __( 'Each: ', 'tier-pricing-table' ),
340 'desc' => __( 'Label for the "each" line.', 'tier-pricing-table' ),
341 'desc_tip' => true,
342 'custom_attributes' => [ 'data-tiered-pricing-premium-setting' => true ]
343 ),
344 array(
345 'title' => __( 'Summary position', 'tier-pricing-table' ),
346 'id' => self::SETTINGS_PREFIX . 'summary_position_hook',
347 'type' => 'select',
348 'options' => array(
349 'woocommerce_before_add_to_cart_button' => __( 'Above buy button', 'tier-pricing-table' ),
350 'woocommerce_after_add_to_cart_button' => __( 'Below buy button', 'tier-pricing-table' ),
351 'woocommerce_before_add_to_cart_form' => __( 'Above add to cart form', 'tier-pricing-table' ),
352 'woocommerce_after_add_to_cart_form' => __( 'Below add to cart form', 'tier-pricing-table' ),
353 'woocommerce_single_product_summary' => __( 'Above product title', 'tier-pricing-table' ),
354 'woocommerce_before_single_product_summary' => __( 'Before product summary', 'tier-pricing-table' ),
355 'woocommerce_after_single_product_summary' => __( 'After product summary', 'tier-pricing-table' ),
356 ),
357 'default' => 'woocommerce_after_add_to_cart_button',
358 'desc' => __( 'Where to display the summary block.', 'tier-pricing-table' ),
359 'desc_tip' => true,
360 'custom_attributes' => [ 'data-tiered-pricing-premium-setting' => true ]
361 ),
362 array(
363 'type' => 'sectionend',
364 'id' => self::SETTINGS_PREFIX . 'premium_options'
365 ),
366 );
367 }
368
369 /**
370 * Register hooks
371 */
372 public function hooks() {
373 add_action( 'init', [ $this, 'initSettings' ] );
374
375 add_filter( 'woocommerce_settings_tabs_' . self::SETTINGS_PAGE, [ $this, 'addTieredPricingTableSettings' ] );
376 add_filter( 'woocommerce_settings_tabs_array', [ $this, 'addSettingsTab' ], 50 );
377 add_action( 'woocommerce_update_options_' . self::SETTINGS_PAGE, [ $this, 'updateSettings' ] );
378 }
379
380 /**
381 * Add own settings tab
382 *
383 * @param array $settings_tabs
384 *
385 * @return mixed
386 */
387 public static function addSettingsTab( $settings_tabs ) {
388
389 $settings_tabs[ self::SETTINGS_PAGE ] = __( 'Tiered Pricing', 'tier-pricing-table' );
390
391 return $settings_tabs;
392 }
393
394 /**
395 * Add settings to WooCommerce
396 */
397 public function addTieredPricingTableSettings() {
398
399 wp_enqueue_script( 'quantity-table-settings-js', $this->fileManager->locateAsset( 'admin/settings.js' ) );
400
401 return woocommerce_admin_fields( $this->settings );
402 }
403
404 /**
405 * Get all settings
406 *
407 * @return array
408 */
409 public function getAll() {
410 return [
411 'display' => $this->get( 'display', 'yes' ),
412 'position_hook' => $this->get( 'position_hook',
413 'woocommerce_after_add_to_cart_button' ),
414 'head_quantity_text' => $this->get( 'head_quantity_text',
415 __( 'Quantity', 'tier-pricing-table' ) ),
416 'head_price_text' => $this->get( 'head_price_text',
417 __( 'Price', 'tier-pricing-table' ) ),
418 'display_type' => $this->get( 'display_type', 'table' ),
419 'selected_quantity_color' => $this->get( 'selected_quantity_color', '#cc99c2' ),
420 'table_title' => $this->get( 'table_title', '' ),
421 'table_css_class' => $this->get( 'table_css_class', '#fff' ),
422 'tooltip_size' => $this->get( 'tooltip_size', 15 ),
423 'tooltip_border' => $this->get( 'tooltip_border', 'yes' ),
424
425 /* Premium */
426 'show_discount_in_cart' => $this->get( 'show_discount_in_cart', 'yes' ),
427 'tiered_price_at_catalog' => $this->get( 'tiered_price_at_catalog', 'yes' ),
428 'tiered_price_at_product_page' => $this->get( 'tiered_price_at_product_page', 'no' ),
429 'tiered_price_at_catalog_for_variable' => $this->get( 'tiered_price_at_catalog_for_variable', 'yes' ),
430 'tiered_price_at_catalog_type' => $this->get( 'tiered_price_at_catalog_type', 'yes' ),
431 'lowest_prefix' => $this->get( 'lowest_prefix', 'yes' ),
432 'show_discount_column' => $this->get( 'show_discount_column', 'yes' ),
433 'clickable_table_rows' => $this->get( 'clickable_table_rows', 'no' ),
434 'show_total_price' => $this->get( 'show_total_price', 'no' ),
435 'head_discount_text' => $this->get( 'head_discount_text',
436 __( 'Discount (%)', 'tier-pricing-table' ) ),
437 ];
438 }
439
440 /**
441 * Get setting by name
442 *
443 * @param string $option_name
444 * @param mixed $default
445 *
446 * @return mixed
447 */
448 public function get( $option_name, $default = null ) {
449 return get_option( self::SETTINGS_PREFIX . $option_name, $default );
450 }
451
452 /**
453 * Get url to settings page
454 *
455 * @return string
456 */
457 public function getLink() {
458 return admin_url( 'admin.php?page=wc-settings&tab=tiered_pricing_table_settings' );
459 }
460 }