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 / ProductCatalogLoop / Settings / ProductCatalogLoopSettingsSection.php

ProductCatalogLoopSettingsSection.php in Tiered Pricing Table for WooCommerce 6.1.0, at src/Addons/ProductCatalogLoop/Settings/ProductCatalogLoopSettingsSection.php

453 lines 16.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php namespace TierPricingTable\Addons\ProductCatalogLoop\Settings;
2
3 use TierPricingTable\Settings\CustomOptions\TPTDisplayType;
4 use TierPricingTable\Settings\CustomOptions\TPTQuantityMeasurementField;
5 use TierPricingTable\Settings\CustomOptions\TPTSwitchOption;
6 use TierPricingTable\Settings\CustomOptions\TPTTextTemplate;
7 use TierPricingTable\Settings\Sections\SectionAbstract;
8 use TierPricingTable\Settings\Settings;
9 use TierPricingTable\TierPricingTablePlugin;
10
11 class ProductCatalogLoopSettingsSection extends SectionAbstract {
12
13 public static function getOptionID( $option ): string {
14 return self::getSettingsPrefix() . $option;
15 }
16
17 public static function getSettingsPrefix(): string {
18 return Settings::SETTINGS_PREFIX . 'shop_loop_display_';
19 }
20
21 public function getName(): string {
22 return __( 'Product Catalog', 'tier-pricing-table' );
23 }
24
25 public function getSlug(): string {
26 return 'shop-loop-display';
27 }
28
29 public function getSettings(): array {
30
31 $availableLayouts = TierPricingTablePlugin::getAvailablePricingLayouts();
32 unset( $availableLayouts['tooltip'] );
33
34 return array(
35 array(
36 'title' => __( 'Tiered Pricing on the shop page', 'tier-pricing-table' ),
37 'desc' => __( 'This section controls how tiered pricing works for product catalog.',
38 'tier-pricing-table' ),
39 'type' => 'title',
40 ),
41 array(
42 'title' => __( 'Enabled', 'tier-pricing-table' ),
43 'id' => self::getOptionID( 'enabled' ),
44 'type' => TPTSwitchOption::FIELD_TYPE,
45 'default' => 'no',
46 'extended_description' => ( function () {
47 ob_start();
48 ?>
49 <p>
50 <?php
51 esc_html_e( 'Enable this option to show tiered pricing in the products catalog.',
52 'tier-pricing-table' );
53 ?>
54 <br>
55 <br>
56 <b><?php esc_html_e( 'Note:', 'tier-pricing-table' ); ?></b>
57 <br>
58 <?php esc_html_e( 'Some themes could display it incorrectly.', 'tier-pricing-table' ); ?>
59 </p>
60 <?php
61 return ob_get_clean();
62 } )(),
63 'desc' => __( 'Show tiered pricing in the product loop (product catalog page)',
64 'tier-pricing-table' ),
65 'desc_tip' => true,
66 ),
67 array(
68 'title' => __( 'Position on a product item', 'tier-pricing-table' ),
69 'id' => self::getOptionID( 'position' ),
70 'type' => 'select',
71 'default' => 'woocommerce_after_shop_loop_item__6',
72 'options' => array(
73 'woocommerce_after_shop_loop_item__6' => __( 'Above add-to-cart button', 'tier-pricing-table' ),
74 'woocommerce_after_shop_loop_item__15' => __( 'Below add-to-cart button', 'tier-pricing-table' ),
75 'woocommerce_shop_loop_item_title__5' => __( 'Above product title', 'tier-pricing-table' ),
76 'woocommerce_shop_loop_item_title__15' => __( 'Below product title', 'tier-pricing-table' ),
77 ),
78 'desc' => __( 'Where tiered pricing should be displayed on the product page.',
79 'tier-pricing-table' ),
80 'desc_tip' => true,
81 ),
82 array(
83 'title' => __( 'Show quantity field', 'tier-pricing-table' ),
84 'id' => self::getOptionID( 'show_quantity_field' ),
85 'type' => TPTSwitchOption::FIELD_TYPE,
86 'default' => 'no',
87 'extended_description' => ( function () {
88 ob_start();
89 ?>
90 <p>
91 <?php
92 esc_html_e( 'Show a quantity field on the product catalog items.', 'tier-pricing-table' );
93 ?>
94 <br>
95 <br>
96 <b>
97 <?php
98 esc_html_e( 'Enable this only if your theme does not show the quantity field already.',
99 'tier-pricing-table' );
100 ?>
101 </b>
102 </p>
103 <?php
104 return ob_get_clean();
105 } )(),
106 'custom_attributes' => [ 'data-tiered-pricing-premium-option' => true ],
107 ),
108 array(
109 'title' => __( 'Dynamic price', 'tier-pricing-table' ),
110 'id' => self::getOptionID( 'dynamic_price' ),
111 'type' => TPTSwitchOption::FIELD_TYPE,
112 'default' => 'yes',
113 'extended_description' => ( function () {
114 ob_start();
115 ?>
116 <p>
117 <?php
118 esc_html_e( 'Similar to the product page, the price will be updated dynamically when the user changes the quantity of a specific item.',
119 'tier-pricing-table' );
120 ?>
121 </p>
122 <?php
123 return ob_get_clean();
124 } )(),
125 'desc_tip' => true,
126 ),
127 array(
128 'title' => __( 'Use reduced styles', 'tier-pricing-table' ),
129 'id' => self::getOptionID( 'use_reduced_styles' ),
130 'type' => TPTSwitchOption::FIELD_TYPE,
131 'default' => 'yes',
132 'desc' => __( 'The plugin will apply additional CSS styles to the pricing layouts displayed in the product catalog to make them compact.',
133 'tier-pricing-table' ),
134 'desc_tip' => true,
135 ),
136 array(
137 'type' => 'sectionend',
138 ),
139
140 array(
141 'title' => __( 'Template options', 'tier-pricing-table' ),
142 'desc' => __( 'Choose a tiered pricing template and customize its look and behavior.',
143 'tier-pricing-table' ),
144 'id' => self::getOptionId( 'layout_settings' ),
145 'type' => 'title',
146 ),
147
148 array(
149 'title' => __( 'Layout settings', 'tier-pricing-table' ),
150 'id' => self::getOptionID( 'layout_settings' ),
151 'type' => TPTDisplayType::FIELD_TYPE,
152 'options' => array(
153 'default' => __( 'Same as for product page', 'tier-pricing-table' ),
154 'custom' => __( 'Custom', 'tier-pricing-table' ),
155 ),
156 'desc' => __( 'The template for tiered pricing for the catalog page. You can use the same template settings as for the product page or choose a different one.',
157 'tier-pricing-table' ),
158 'desc_tip' => true,
159 'default' => 'default',
160 ),
161 array(
162 'title' => __( 'Layout', 'tier-pricing-table' ),
163 'id' => self::getOptionID( 'layout' ),
164 'type' => TPTDisplayType::FIELD_TYPE,
165 'options' => $availableLayouts,
166 'desc' => __( 'Template for tiered pricing on the catalog page.', 'tier-pricing-table' ),
167 'desc_tip' => true,
168 'default' => 'table',
169 ),
170 array(
171 'title' => __( 'Pricing title', 'tier-pricing-table' ),
172 'id' => self::getOptionID( 'title' ),
173 'type' => 'text',
174 'default' => '',
175 'desc' => __( 'The pricing title that is displayed above the tiered pricing.',
176 'tier-pricing-table' ),
177 ),
178 array(
179 'title' => __( 'Quantity display type', 'tier-pricing-table' ),
180 'id' => self::getOptionID( 'quantity_type' ),
181 'type' => TPTDisplayType::FIELD_TYPE,
182 'options' => array(
183 'range' => __( 'Range', 'tier-pricing-table' ),
184 'static' => __( 'Static values', 'tier-pricing-table' ),
185 ),
186 'desc' => __( '"Range" displays the quantity range a tier applies to. "Static" displays only the minimum quantity required.',
187 'tier-pricing-table' ),
188 'default' => 'range',
189 ),
190 array(
191 'title' => __( 'Active pricing tier color', 'tier-pricing-table' ),
192 'id' => self::getOptionID( 'selected_quantity_color' ),
193 'type' => 'color',
194 'css' => 'width:6em;',
195 'default' => '#96598A',
196 ),
197 array(
198 'title' => __( 'Unit label', 'tier-pricing-table' ),
199 'id' => self::getOptionID( 'table_quantity_measurement' ),
200 'type' => TPTQuantityMeasurementField::FIELD_TYPE,
201 'default' => array(
202 'singular' => '',
203 'plural' => '',
204 ),
205 'desc' => __( 'For example: pieces, boxes, bottles, packs, etc. This will be shown next to quantity values. Leave blank to skip adding a unit label.',
206 'tier-pricing-table' ),
207 ),
208 array(
209 'title' => __( 'Unit label', 'tier-pricing-table' ),
210 'id' => self::getOptionID( 'blocks_quantity_measurement' ),
211 'type' => TPTQuantityMeasurementField::FIELD_TYPE,
212 'default' => array(
213 'singular' => _n( 'piece', 'pieces', 1, 'tier-pricing-table' ),
214 'plural' => _n( 'piece', 'pieces', 2, 'tier-pricing-table' ),
215 ),
216 'desc' => __( 'For example: pieces, boxes, bottles, packs, etc. This will be shown next to quantity values. Leave blank to skip adding a unit label.',
217 'tier-pricing-table' ),
218 ),
219 array(
220 'title' => __( 'Quantity column title', 'tier-pricing-table' ),
221 'default' => __( 'Quantity', 'tier-pricing-table' ),
222 'id' => self::getOptionID( 'quantity_column_title' ),
223 'desc' => __( 'Leave empty to not show this column.', 'tier-pricing-table' ),
224 'type' => 'text',
225 ),
226 array(
227 'title' => __( 'Discount column title', 'tier-pricing-table' ),
228 'default' => __( 'Discount', 'tier-pricing-table' ),
229 'id' => self::getOptionID( 'discount_column_title' ),
230 'desc' => __( 'Leave empty to not show this column.', 'tier-pricing-table' ),
231 'type' => 'text',
232 ),
233 array(
234 'title' => __( 'Price column title', 'tier-pricing-table' ),
235 'default' => __( 'Price', 'tier-pricing-table' ),
236 'id' => self::getOptionID( 'price_column_title' ),
237 'desc' => __( 'Leave empty to not show this column.', 'tier-pricing-table' ),
238 'type' => 'text',
239 ),
240 array(
241 'title' => __( 'Show percentage discount', 'tier-pricing-table' ),
242 'id' => self::getOptionID( 'blocks_show_discount' ),
243 'type' => TPTSwitchOption::FIELD_TYPE,
244 'default' => 'yes',
245 ),
246 array(
247 'title' => __( 'Show regular product price', 'tier-pricing-table' ),
248 'id' => self::getOptionID( 'options_show_original_product_price' ),
249 'type' => TPTSwitchOption::FIELD_TYPE,
250 'default' => 'yes',
251 'desc' => __( 'Show the crossed out regular price in options.', 'tier-pricing-table' ),
252 ),
253 array(
254 'title' => __( 'Show total pricing in option', 'tier-pricing-table' ),
255 'id' => self::getOptionID( 'options_show_total' ),
256 'type' => TPTSwitchOption::FIELD_TYPE,
257 'default' => 'yes',
258 'desc' => __( 'Show the total price in an active option.', 'tier-pricing-table' ),
259 'custom_attributes' => [ 'data-tiered-pricing-premium-option' => true ],
260 ),
261 array(
262 'title' => __( 'Option template', 'tier-pricing-table' ),
263 'id' => self::getOptionID( 'options_option_text' ),
264 'default' => __( '<strong>Buy {tp_quantity} pieces and save {tp_rounded_discount}%</strong>',
265 'tier-pricing-table' ),
266 'placeholders' => array(
267 'tp_quantity',
268 'tp_discount',
269 'tp_rounded_discount',
270 ),
271 'type' => TPTTextTemplate::FIELD_TYPE,
272 ),
273 array(
274 'title' => __( 'Show the "no discount" option', 'tier-pricing-table' ),
275 'id' => self::getOptionID( 'options_show_default_option' ),
276 'type' => TPTSwitchOption::FIELD_TYPE,
277 'default' => 'yes',
278 'desc' => __( 'Show the option with a regular product price.', 'tier-pricing-table' ),
279 ),
280 array(
281 'title' => __( '"No discount" option template', 'tier-pricing-table' ),
282 'id' => self::getOptionID( 'options_default_option_text' ),
283 'default' => __( '<strong>Buy {tp_quantity} pieces</strong>', 'tier-pricing-table' ),
284 'placeholders' => array(
285 'tp_quantity',
286 ),
287 'type' => TPTTextTemplate::FIELD_TYPE,
288 ),
289 array(
290 'title' => __( 'Template', 'tier-pricing-table' ),
291 'id' => self::getOptionID( 'plain_text_template' ),
292 'default' => __( '<strong>Buy {tp_quantity} pieces for {tp_price} each and save {tp_rounded_discount}%</strong>',
293 'tier-pricing-table' ),
294 'placeholders' => array(
295 'tp_quantity',
296 'tp_discount',
297 'tp_price',
298 'tp_rounded_discount',
299 ),
300 'type' => TPTTextTemplate::FIELD_TYPE,
301 ),
302
303 array(
304 'title' => __( 'Show the "no discount" tier', 'tier-pricing-table' ),
305 'id' => self::getOptionID( 'plain_text_show_first_tier' ),
306 'type' => TPTSwitchOption::FIELD_TYPE,
307 'default' => 'yes',
308 'desc' => __( 'Show the tier with a regular product price.', 'tier-pricing-table' ),
309 ),
310
311 array(
312 'title' => __( '"No discount" template', 'tier-pricing-table' ),
313 'id' => self::getOptionID( 'plain_text_first_tier_template' ),
314 'default' => __( '<strong>Buy {tp_quantity} pieces for {tp_price} each</strong>',
315 'tier-pricing-table' ),
316 'placeholders' => array(
317 'tp_quantity',
318 'tp_price',
319 ),
320 'type' => TPTTextTemplate::FIELD_TYPE,
321 ),
322 array(
323 'title' => __( 'Clickable tiered pricing', 'tier-pricing-table' ),
324 'id' => self::getOptionID( 'clickable_table_rows' ),
325 'type' => TPTSwitchOption::FIELD_TYPE,
326 'default' => 'yes',
327 'desc' => __( 'Makes tiered pricing (table rows, blocks, options, etc) clickable.',
328 'tier-pricing-table' ),
329 'custom_attributes' => [ 'data-tiered-pricing-premium-option' => true ],
330 ),
331 array(
332 'type' => 'sectionend',
333 ),
334 );
335 }
336
337 public static function isEnabled(): bool {
338 return 'yes' === get_option( self::getOptionID( 'enabled' ), 'no' );
339 }
340
341 public static function getPosition(): array {
342 $hook = get_option( self::getOptionID( 'position' ), 'woocommerce_after_shop_loop_item__6' );
343
344 $hook = explode( '__', $hook );
345
346 return array(
347 'hook' => ! empty( $hook[0] ) ? $hook[0] : '__none__',
348 'priority' => ! empty( $hook[1] ) ? $hook[1] : 15,
349 );
350 }
351
352 public static function isCustomLayoutSettings(): bool {
353 return 'custom' === get_option( self::getOptionID( 'layout_settings' ), 'default' );
354 }
355
356 public static function getLayoutType(): string {
357 return get_option( self::getOptionID( 'layout' ), 'table' );
358 }
359
360 public static function getTitle(): string {
361 return get_option( self::getOptionID( 'title' ), '' );
362 }
363
364 public static function getQuantityType(): string {
365 return get_option( self::getOptionID( 'quantity_type' ), 'range' );
366 }
367
368 public static function getSelectedQuantityColor(): string {
369 return get_option( self::getOptionID( 'selected_quantity_color' ), '#96598A' );
370 }
371
372 public static function getTableQuantityMeasurement(): array {
373 return get_option( self::getOptionID( 'table_quantity_measurement' ), array(
374 'singular' => '',
375 'plural' => '',
376 ) );
377 }
378
379 public static function getBlocksQuantityMeasurement(): array {
380 return get_option( self::getOptionID( 'blocks_quantity_measurement' ), array(
381 'singular' => _n( 'piece', 'pieces', 1, 'tier-pricing-table' ),
382 'plural' => _n( 'piece', 'pieces', 2, 'tier-pricing-table' ),
383 ) );
384 }
385
386 public static function getTableColumnsTitles(): array {
387 return array(
388 'head_quantity_text' => get_option( self::getOptionID( 'quantity_column_title' ),
389 __( 'Quantity', 'tier-pricing-table' ) ),
390 'head_discount_text' => get_option( self::getOptionID( 'discount_column_title' ),
391 __( 'Discount', 'tier-pricing-table' ) ),
392 'head_price_text' => get_option( self::getOptionID( 'price_column_title' ),
393 __( 'Price', 'tier-pricing-table' ) ),
394 );
395 }
396
397 public static function blocksShowDiscount(): bool {
398 return 'yes' === get_option( self::getOptionID( 'blocks_show_discount' ), 'yes' );
399 }
400
401 public static function isShowOriginalProductPriceInOptions(): bool {
402 return 'yes' === get_option( self::getOptionID( 'options_show_original_product_price' ), 'yes' );
403 }
404
405 public static function isShowTotalInOptions(): bool {
406 return 'yes' === get_option( self::getOptionID( 'options_show_total' ), 'yes' );
407 }
408
409 public static function getOptionText(): string {
410 return get_option( self::getOptionID( 'options_option_text' ),
411 '<strong>Buy {tp_quantity} pieces and save {tp_rounded_discount}%</strong>' );
412 }
413
414 public static function isShowDefaultOption(): bool {
415 return 'yes' === get_option( self::getOptionID( 'options_show_default_option' ), 'yes' );
416 }
417
418 public static function getDefaultOptionText(): string {
419 return get_option( self::getOptionID( 'options_default_option_text' ),
420 '<strong>Buy {tp_quantity} pieces</strong>' );
421 }
422
423 public static function getPlainTextTemplate(): string {
424 return get_option( self::getOptionID( 'plain_text_template' ),
425 '<strong>Buy {tp_quantity} pieces for {tp_price} each and save {tp_rounded_discount}%</strong>' );
426 }
427
428 public static function isShowFirstPlainTextTier(): bool {
429 return 'yes' === get_option( self::getOptionID( 'plain_text_show_first_tier' ), 'yes' );
430 }
431
432 public static function getFirstTierPlainTextTemplate(): string {
433 return get_option( self::getOptionID( 'plain_text_first_tier_template' ),
434 '<strong>Buy {tp_quantity} pieces for {tp_price} each</strong>' );
435 }
436
437 public static function isClickableTableRows(): bool {
438 return 'yes' === get_option( self::getOptionID( 'clickable_table_rows' ), 'yes' );
439 }
440
441 public static function useReducedStyles(): bool {
442 return 'yes' === get_option( self::getOptionID( 'use_reduced_styles' ), 'yes' );
443 }
444
445 public static function isDynamicPrice(): bool {
446 return 'yes' === get_option( self::getOptionID( 'dynamic_price' ), 'yes' );
447 }
448
449 public static function showQuantityField(): bool {
450 return 'yes' === get_option( self::getOptionID( 'show_quantity_field' ), 'no' );
451 }
452
453 }