PluginProbe
Tiered Pricing Table for WooCommerce / 6.5.0
Tiered Pricing Table for WooCommerce v6.5.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.5.0, at src/Addons/ProductCatalogLoop/Settings/ProductCatalogLoopSettingsSection.php

452 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 __( 'Catalog Display', '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' => __( 'Control how tiered pricing appears on shop and category pages.',
38 'tier-pricing-table' ),
39 'type' => 'title',
40 ),
41 array(
42 'title' => __( 'Enable on catalog pages', '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( 'Turn this on to display tiered pricing directly within your product catalog.',
52 'tier-pricing-table' );
53 ?>
54 </p>
55 <p>
56 <b><?php esc_html_e( 'Note:', 'tier-pricing-table' ); ?></b>
57 <?php esc_html_e( 'Depending on your theme, you may need minor CSS adjustments for optimal display.', 'tier-pricing-table' ); ?>
58 </p>
59 <?php
60 return ob_get_clean();
61 } )(),
62 'desc' => __( 'Display tiered pricing tables on shop and category pages.',
63 'tier-pricing-table' ),
64 'desc_tip' => true,
65 ),
66 array(
67 'title' => __( 'Position on catalog item', 'tier-pricing-table' ),
68 'id' => self::getOptionID( 'position' ),
69 'type' => 'select',
70 'default' => 'woocommerce_after_shop_loop_item__6',
71 'options' => array(
72 'woocommerce_after_shop_loop_item__6' => __( 'Above add-to-cart button', 'tier-pricing-table' ),
73 'woocommerce_after_shop_loop_item__15' => __( 'Below add-to-cart button', 'tier-pricing-table' ),
74 'woocommerce_shop_loop_item_title__5' => __( 'Above product title', 'tier-pricing-table' ),
75 'woocommerce_shop_loop_item_title__15' => __( 'Below product title', 'tier-pricing-table' ),
76 ),
77 'desc' => __( 'Choose where the tiered pricing table appears relative to the product image and details.',
78 'tier-pricing-table' ),
79 'desc_tip' => true,
80 ),
81 array(
82 'title' => __( 'Add quantity selector', 'tier-pricing-table' ),
83 'id' => self::getOptionID( 'show_quantity_field' ),
84 'type' => TPTSwitchOption::FIELD_TYPE,
85 'default' => 'no',
86 'extended_description' => ( function () {
87 ob_start();
88 ?>
89 <p>
90 <?php
91 esc_html_e( 'Add a quantity input field directly to items in the product catalog.', 'tier-pricing-table' );
92 ?>
93 </p>
94 <p>
95 <b>
96 <?php
97 esc_html_e( 'Only enable this if your theme doesn\'t already provide quantity selectors on the shop page.',
98 'tier-pricing-table' );
99 ?>
100 </b>
101 </p>
102 <?php
103 return ob_get_clean();
104 } )(),
105 'custom_attributes' => [ 'data-tiered-pricing-premium-option' => true ],
106 ),
107 array(
108 'title' => __( 'Dynamic total price', 'tier-pricing-table' ),
109 'id' => self::getOptionID( 'dynamic_price' ),
110 'type' => TPTSwitchOption::FIELD_TYPE,
111 'default' => 'yes',
112 'extended_description' => ( function () {
113 ob_start();
114 ?>
115 <p>
116 <?php
117 esc_html_e( 'Automatically update the displayed price when a customer changes the quantity from the catalog.',
118 'tier-pricing-table' );
119 ?>
120 </p>
121 <?php
122 return ob_get_clean();
123 } )(),
124 'desc_tip' => true,
125 ),
126 array(
127 'title' => __( 'Compact layout', 'tier-pricing-table' ),
128 'id' => self::getOptionID( 'use_reduced_styles' ),
129 'type' => TPTSwitchOption::FIELD_TYPE,
130 'default' => 'yes',
131 'desc' => __( 'Apply minimal styling to pricing tables to better fit the constrained space of catalog grids.',
132 'tier-pricing-table' ),
133 'desc_tip' => true,
134 ),
135 array(
136 'type' => 'sectionend',
137 ),
138
139 array(
140 'title' => __( 'Pricing Layout Settings', 'tier-pricing-table' ),
141 'desc' => __( 'Customize the appearance and behavior of tiered pricing on catalog pages.',
142 'tier-pricing-table' ),
143 'id' => self::getOptionId( 'layout_settings' ),
144 'type' => 'title',
145 ),
146
147 array(
148 'title' => __( 'Layout source', 'tier-pricing-table' ),
149 'id' => self::getOptionID( 'layout_settings' ),
150 'type' => TPTDisplayType::FIELD_TYPE,
151 'options' => array(
152 'default' => __( 'Same as product page', 'tier-pricing-table' ),
153 'custom' => __( 'Custom', 'tier-pricing-table' ),
154 ),
155 'desc' => __( 'Choose whether to inherit the layout from the product page or use a custom layout for catalogs.',
156 'tier-pricing-table' ),
157 'desc_tip' => true,
158 'default' => 'default',
159 ),
160 array(
161 'title' => __( 'Catalog layout', 'tier-pricing-table' ),
162 'id' => self::getOptionID( 'layout' ),
163 'type' => TPTDisplayType::FIELD_TYPE,
164 'options' => $availableLayouts,
165 'desc' => __( 'Select the specific visual template for the catalog page.', 'tier-pricing-table' ),
166 'desc_tip' => true,
167 'default' => 'table',
168 ),
169 array(
170 'title' => __( 'Pricing title', 'tier-pricing-table' ),
171 'id' => self::getOptionID( 'title' ),
172 'type' => 'text',
173 'default' => '',
174 'desc' => __( 'Text displayed above the tiered pricing block.',
175 'tier-pricing-table' ),
176 ),
177 array(
178 'title' => __( 'Quantity display type', 'tier-pricing-table' ),
179 'id' => self::getOptionID( 'quantity_type' ),
180 'type' => TPTDisplayType::FIELD_TYPE,
181 'options' => array(
182 'range' => __( 'Range', 'tier-pricing-table' ),
183 'static' => __( 'Static values', 'tier-pricing-table' ),
184 ),
185 'desc' => __( '"Range" displays the quantity range a tier applies to. "Static" displays only the minimum quantity required.',
186 'tier-pricing-table' ),
187 'default' => 'range',
188 ),
189 array(
190 'title' => __( 'Active pricing tier color', 'tier-pricing-table' ),
191 'id' => self::getOptionID( 'selected_quantity_color' ),
192 'type' => 'color',
193 'css' => 'width:6em;',
194 'default' => '#3858e9',
195 ),
196 array(
197 'title' => __( 'Unit label', 'tier-pricing-table' ),
198 'id' => self::getOptionID( 'table_quantity_measurement' ),
199 'type' => TPTQuantityMeasurementField::FIELD_TYPE,
200 'default' => array(
201 'singular' => '',
202 'plural' => '',
203 ),
204 'desc' => __( 'For example: pieces, boxes, bottles, packs, etc. This will be shown next to quantity values. Leave blank to skip adding a unit label.',
205 'tier-pricing-table' ),
206 ),
207 array(
208 'title' => __( 'Unit label', 'tier-pricing-table' ),
209 'id' => self::getOptionID( 'blocks_quantity_measurement' ),
210 'type' => TPTQuantityMeasurementField::FIELD_TYPE,
211 'default' => array(
212 'singular' => _n( 'piece', 'pieces', 1, 'tier-pricing-table' ),
213 'plural' => _n( 'piece', 'pieces', 2, 'tier-pricing-table' ),
214 ),
215 'desc' => __( 'For example: pieces, boxes, bottles, packs, etc. This will be shown next to quantity values. Leave blank to skip adding a unit label.',
216 'tier-pricing-table' ),
217 ),
218 array(
219 'title' => __( 'Quantity column title', 'tier-pricing-table' ),
220 'default' => __( 'Quantity', 'tier-pricing-table' ),
221 'id' => self::getOptionID( 'quantity_column_title' ),
222 'desc' => __( 'Leave empty to not show this column.', 'tier-pricing-table' ),
223 'type' => 'text',
224 ),
225 array(
226 'title' => __( 'Discount column title', 'tier-pricing-table' ),
227 'default' => __( 'Discount', 'tier-pricing-table' ),
228 'id' => self::getOptionID( 'discount_column_title' ),
229 'desc' => __( 'Leave empty to not show this column.', 'tier-pricing-table' ),
230 'type' => 'text',
231 ),
232 array(
233 'title' => __( 'Price column title', 'tier-pricing-table' ),
234 'default' => __( 'Price', 'tier-pricing-table' ),
235 'id' => self::getOptionID( 'price_column_title' ),
236 'desc' => __( 'Leave empty to not show this column.', 'tier-pricing-table' ),
237 'type' => 'text',
238 ),
239 array(
240 'title' => __( 'Show percentage discount', 'tier-pricing-table' ),
241 'id' => self::getOptionID( 'blocks_show_discount' ),
242 'type' => TPTSwitchOption::FIELD_TYPE,
243 'default' => 'yes',
244 ),
245 array(
246 'title' => __( 'Show regular product price', 'tier-pricing-table' ),
247 'id' => self::getOptionID( 'options_show_original_product_price' ),
248 'type' => TPTSwitchOption::FIELD_TYPE,
249 'default' => 'yes',
250 'desc' => __( 'Show the crossed out regular price in options.', 'tier-pricing-table' ),
251 ),
252 array(
253 'title' => __( 'Show total pricing in option', 'tier-pricing-table' ),
254 'id' => self::getOptionID( 'options_show_total' ),
255 'type' => TPTSwitchOption::FIELD_TYPE,
256 'default' => 'yes',
257 'desc' => __( 'Show the total price in an active option.', 'tier-pricing-table' ),
258 'custom_attributes' => [ 'data-tiered-pricing-premium-option' => true ],
259 ),
260 array(
261 'title' => __( 'Option template', 'tier-pricing-table' ),
262 'id' => self::getOptionID( 'options_option_text' ),
263 'default' => __( '<strong>Buy {tp_quantity} pieces and save {tp_rounded_discount}%</strong>',
264 'tier-pricing-table' ),
265 'placeholders' => array(
266 'tp_quantity',
267 'tp_discount',
268 'tp_rounded_discount',
269 ),
270 'type' => TPTTextTemplate::FIELD_TYPE,
271 ),
272 array(
273 'title' => __( 'Show the "no discount" option', 'tier-pricing-table' ),
274 'id' => self::getOptionID( 'options_show_default_option' ),
275 'type' => TPTSwitchOption::FIELD_TYPE,
276 'default' => 'yes',
277 'desc' => __( 'Show the option with a regular product price.', 'tier-pricing-table' ),
278 ),
279 array(
280 'title' => __( '"No discount" option template', 'tier-pricing-table' ),
281 'id' => self::getOptionID( 'options_default_option_text' ),
282 'default' => __( '<strong>Buy {tp_quantity} pieces</strong>', 'tier-pricing-table' ),
283 'placeholders' => array(
284 'tp_quantity',
285 ),
286 'type' => TPTTextTemplate::FIELD_TYPE,
287 ),
288 array(
289 'title' => __( 'Template', 'tier-pricing-table' ),
290 'id' => self::getOptionID( 'plain_text_template' ),
291 'default' => __( '<strong>Buy {tp_quantity} pieces for {tp_price} each and save {tp_rounded_discount}%</strong>',
292 'tier-pricing-table' ),
293 'placeholders' => array(
294 'tp_quantity',
295 'tp_discount',
296 'tp_price',
297 'tp_rounded_discount',
298 ),
299 'type' => TPTTextTemplate::FIELD_TYPE,
300 ),
301
302 array(
303 'title' => __( 'Show the "no discount" tier', 'tier-pricing-table' ),
304 'id' => self::getOptionID( 'plain_text_show_first_tier' ),
305 'type' => TPTSwitchOption::FIELD_TYPE,
306 'default' => 'yes',
307 'desc' => __( 'Show the tier with a regular product price.', 'tier-pricing-table' ),
308 ),
309
310 array(
311 'title' => __( '"No discount" template', 'tier-pricing-table' ),
312 'id' => self::getOptionID( 'plain_text_first_tier_template' ),
313 'default' => __( '<strong>Buy {tp_quantity} pieces for {tp_price} each</strong>',
314 'tier-pricing-table' ),
315 'placeholders' => array(
316 'tp_quantity',
317 'tp_price',
318 ),
319 'type' => TPTTextTemplate::FIELD_TYPE,
320 ),
321 array(
322 'title' => __( 'Clickable tiered pricing', 'tier-pricing-table' ),
323 'id' => self::getOptionID( 'clickable_table_rows' ),
324 'type' => TPTSwitchOption::FIELD_TYPE,
325 'default' => 'yes',
326 'desc' => __( 'Makes tiered pricing (table rows, blocks, options, etc) clickable.',
327 'tier-pricing-table' ),
328 'custom_attributes' => [ 'data-tiered-pricing-premium-option' => true ],
329 ),
330 array(
331 'type' => 'sectionend',
332 ),
333 );
334 }
335
336 public static function isEnabled(): bool {
337 return 'yes' === get_option( self::getOptionID( 'enabled' ), 'no' );
338 }
339
340 public static function getPosition(): array {
341 $hook = get_option( self::getOptionID( 'position' ), 'woocommerce_after_shop_loop_item__6' );
342
343 $hook = explode( '__', $hook );
344
345 return array(
346 'hook' => ! empty( $hook[0] ) ? $hook[0] : '__none__',
347 'priority' => ! empty( $hook[1] ) ? $hook[1] : 15,
348 );
349 }
350
351 public static function isCustomLayoutSettings(): bool {
352 return 'custom' === get_option( self::getOptionID( 'layout_settings' ), 'default' );
353 }
354
355 public static function getLayoutType(): string {
356 return get_option( self::getOptionID( 'layout' ), 'table' );
357 }
358
359 public static function getTitle(): string {
360 return get_option( self::getOptionID( 'title' ), '' );
361 }
362
363 public static function getQuantityType(): string {
364 return get_option( self::getOptionID( 'quantity_type' ), 'range' );
365 }
366
367 public static function getSelectedQuantityColor(): string {
368 return get_option( self::getOptionID( 'selected_quantity_color' ), '#3858e9' );
369 }
370
371 public static function getTableQuantityMeasurement(): array {
372 return get_option( self::getOptionID( 'table_quantity_measurement' ), array(
373 'singular' => '',
374 'plural' => '',
375 ) );
376 }
377
378 public static function getBlocksQuantityMeasurement(): array {
379 return get_option( self::getOptionID( 'blocks_quantity_measurement' ), array(
380 'singular' => _n( 'piece', 'pieces', 1, 'tier-pricing-table' ),
381 'plural' => _n( 'piece', 'pieces', 2, 'tier-pricing-table' ),
382 ) );
383 }
384
385 public static function getTableColumnsTitles(): array {
386 return array(
387 'head_quantity_text' => get_option( self::getOptionID( 'quantity_column_title' ),
388 __( 'Quantity', 'tier-pricing-table' ) ),
389 'head_discount_text' => get_option( self::getOptionID( 'discount_column_title' ),
390 __( 'Discount', 'tier-pricing-table' ) ),
391 'head_price_text' => get_option( self::getOptionID( 'price_column_title' ),
392 __( 'Price', 'tier-pricing-table' ) ),
393 );
394 }
395
396 public static function blocksShowDiscount(): bool {
397 return 'yes' === get_option( self::getOptionID( 'blocks_show_discount' ), 'yes' );
398 }
399
400 public static function isShowOriginalProductPriceInOptions(): bool {
401 return 'yes' === get_option( self::getOptionID( 'options_show_original_product_price' ), 'yes' );
402 }
403
404 public static function isShowTotalInOptions(): bool {
405 return 'yes' === get_option( self::getOptionID( 'options_show_total' ), 'yes' );
406 }
407
408 public static function getOptionText(): string {
409 return get_option( self::getOptionID( 'options_option_text' ),
410 '<strong>Buy {tp_quantity} pieces and save {tp_rounded_discount}%</strong>' );
411 }
412
413 public static function isShowDefaultOption(): bool {
414 return 'yes' === get_option( self::getOptionID( 'options_show_default_option' ), 'yes' );
415 }
416
417 public static function getDefaultOptionText(): string {
418 return get_option( self::getOptionID( 'options_default_option_text' ),
419 '<strong>Buy {tp_quantity} pieces</strong>' );
420 }
421
422 public static function getPlainTextTemplate(): string {
423 return get_option( self::getOptionID( 'plain_text_template' ),
424 '<strong>Buy {tp_quantity} pieces for {tp_price} each and save {tp_rounded_discount}%</strong>' );
425 }
426
427 public static function isShowFirstPlainTextTier(): bool {
428 return 'yes' === get_option( self::getOptionID( 'plain_text_show_first_tier' ), 'yes' );
429 }
430
431 public static function getFirstTierPlainTextTemplate(): string {
432 return get_option( self::getOptionID( 'plain_text_first_tier_template' ),
433 '<strong>Buy {tp_quantity} pieces for {tp_price} each</strong>' );
434 }
435
436 public static function isClickableTableRows(): bool {
437 return 'yes' === get_option( self::getOptionID( 'clickable_table_rows' ), 'yes' );
438 }
439
440 public static function useReducedStyles(): bool {
441 return 'yes' === get_option( self::getOptionID( 'use_reduced_styles' ), 'yes' );
442 }
443
444 public static function isDynamicPrice(): bool {
445 return 'yes' === get_option( self::getOptionID( 'dynamic_price' ), 'yes' );
446 }
447
448 public static function showQuantityField(): bool {
449 return 'yes' === get_option( self::getOptionID( 'show_quantity_field' ), 'no' );
450 }
451
452 }