PluginProbe
Tiered Pricing Table for WooCommerce / 2.2.1
Tiered Pricing Table for WooCommerce v2.2.1
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.2.1, at src/Settings/Settings.php

355 lines 13.1 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 '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 ],
164
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 Tiered Pricing on catalog', 'tier-pricing-table' ),
183 'id' => self::SETTINGS_PREFIX . 'tiered_price_at_catalog',
184 'type' => 'checkbox',
185 'default' => 'yes',
186 'desc' => __( 'Shows Tiered Pricing at the Catalog',
187 'tier-pricing-table' ),
188 'desc_tip' => true,
189 'custom_attributes' => [ 'data-tiered-pricing-premium-setting' => true ]
190 ],
191 [
192 'title' => __( 'Enable Catalog Tiered Pricing for Variable Products',
193 'tier-pricing-table' ),
194 'id' => self::SETTINGS_PREFIX . 'tiered_price_at_catalog_for_variable',
195 'type' => 'checkbox',
196 'default' => 'yes',
197 'desc' => __( 'Show tiered price at the catalog for variable products. Uses the lowest and the highest prices from all variations',
198 'tier-pricing-table' ),
199 'desc_tip' => true,
200 'custom_attributes' => [ 'data-tiered-pricing-premium-setting' => true ]
201 ],
202 [
203 'title' => __( 'Display Tiered Price as', 'tier-pricing-table' ),
204 'id' => self::SETTINGS_PREFIX . 'tiered_price_at_catalog_type',
205 'type' => 'select',
206 'options' => [
207 'range' => __( 'Range (from lowest to highest)', 'tier-pricing-table' ),
208 'lowest' => __( 'Lowest price', 'tier-pricing-table' ),
209 ],
210 'desc' => __( 'How to Display Tiered Price at The Catalog', 'tier-pricing-table' ),
211 'desc_tip' => true,
212 'custom_attributes' => [ 'data-tiered-pricing-premium-setting' => true ]
213 ],
214 [
215 'title' => __( 'Lowest price prefix', 'tier-pricing-table' ),
216 'id' => self::SETTINGS_PREFIX . 'lowest_prefix',
217 'type' => 'text',
218 'default' => __( 'From', 'tier-pricing-table' ),
219 'desc' => __( 'Prefix Before Lowest Tiered Product Price at the Catalog. Example: <b>From 10$</b>',
220 'tier-pricing-table' ),
221 'desc_tip' => true,
222 'custom_attributes' => [ 'data-tiered-pricing-premium-setting' => true ]
223 ],
224 [
225 'title' => __( 'Show discount column for percentage table', 'tier-pricing-table' ),
226 'id' => self::SETTINGS_PREFIX . 'show_discount_column',
227 'type' => 'checkbox',
228 'default' => 'yes',
229 'custom_attributes' => [ 'data-tiered-pricing-premium-setting' => true ]
230 ],
231 [
232 'title' => __( 'Discount column text', 'tier-pricing-table' ),
233 'id' => self::SETTINGS_PREFIX . 'head_discount_text',
234 'type' => 'text',
235 'default' => __( 'Discount (%)', 'tier-pricing-table' ),
236 'desc' => __( 'Name of discount column', 'tier-pricing-table' ),
237 'desc_tip' => true,
238 'custom_attributes' => [ 'data-tiered-pricing-premium-setting' => true ]
239 ],
240 [
241 'title' => __( 'Set tiered price on click', 'tier-pricing-table' ),
242 'id' => self::SETTINGS_PREFIX . 'clickable_table_rows',
243 'type' => 'checkbox',
244 'default' => 'no',
245 'desc' => __( 'Change product quantity on click at table pricing row',
246 'tier-pricing-table' ),
247 'custom_attributes' => [ 'data-tiered-pricing-premium-setting' => true ]
248 ],
249 [
250 'title' => __( 'Show total price', 'tier-pricing-table' ),
251 'id' => self::SETTINGS_PREFIX . 'show_total_price',
252 'type' => 'checkbox',
253 'default' => 'no',
254 'desc' => __( 'Calculate and show total price at product page',
255 'tier-pricing-table' ),
256 'custom_attributes' => [ 'data-tiered-pricing-premium-setting' => true ]
257 ],
258 [
259 'type' => 'sectionend',
260 'id' => self::SETTINGS_PREFIX . 'premium_options'
261 ],
262 );
263 }
264
265 /**
266 * Register hooks
267 */
268 public function hooks() {
269 add_action( 'init', [ $this, 'initSettings' ] );
270
271 add_filter( 'woocommerce_settings_tabs_' . self::SETTINGS_PAGE, [ $this, 'addTieredPricingTableSettings' ] );
272 add_filter( 'woocommerce_settings_tabs_array', [ $this, 'addSettingsTab' ], 50 );
273 add_action( 'woocommerce_update_options_' . self::SETTINGS_PAGE, [ $this, 'updateSettings' ] );
274 }
275
276 /**
277 * Add own settings tab
278 *
279 * @param array $settings_tabs
280 *
281 * @return mixed
282 */
283 public static function addSettingsTab( $settings_tabs ) {
284
285 $settings_tabs[ self::SETTINGS_PAGE ] = __( 'Tiered Pricing', 'tier-pricing-table' );
286
287 return $settings_tabs;
288 }
289
290 /**
291 * Add settings to WooCommerce
292 */
293 public function addTieredPricingTableSettings() {
294
295 wp_enqueue_script( 'quantity-table-settings-js', $this->fileManager->locateAsset( 'admin/settings.js' ) );
296
297 return woocommerce_admin_fields( $this->settings );
298 }
299
300 /**
301 * Get all settings
302 *
303 * @return array
304 */
305 public function getAll() {
306 return [
307 'display' => $this->get( 'display', 'yes' ),
308 'position_hook' => $this->get( 'position_hook',
309 'woocommerce_after_add_to_cart_button' ),
310 'head_quantity_text' => $this->get( 'head_quantity_text',
311 __( 'Quantity', 'tier-pricing-table' ) ),
312 'head_price_text' => $this->get( 'head_price_text',
313 __( 'Price', 'tier-pricing-table' ) ),
314 'display_type' => $this->get( 'display_type', 'table' ),
315 'selected_quantity_color' => $this->get( 'selected_quantity_color', '#cc99c2' ),
316 'table_title' => $this->get( 'table_title', '' ),
317 'table_css_class' => $this->get( 'table_css_class', '#fff' ),
318 'tooltip_size' => $this->get( 'tooltip_size', 15 ),
319 'tooltip_border' => $this->get( 'tooltip_border', 'yes' ),
320
321 /* Premium */
322 'show_discount_in_cart' => $this->get( 'show_discount_in_cart', 'yes' ),
323 'tiered_price_at_catalog' => $this->get( 'tiered_price_at_catalog', 'yes' ),
324 'tiered_price_at_catalog_for_variable' => $this->get( 'tiered_price_at_catalog_for_variable', 'yes' ),
325 'tiered_price_at_catalog_type' => $this->get( 'tiered_price_at_catalog_type', 'yes' ),
326 'lowest_prefix' => $this->get( 'lowest_prefix', 'yes' ),
327 'show_discount_column' => $this->get( 'show_discount_column', 'yes' ),
328 'clickable_table_rows' => $this->get( 'clickable_table_rows', 'no' ),
329 'show_total_price' => $this->get( 'show_total_price', 'no' ),
330 'head_discount_text' => $this->get( 'head_discount_text',
331 __( 'Discount (%)', 'tier-pricing-table' ) ),
332 ];
333 }
334
335 /**
336 * Get setting by name
337 *
338 * @param string $option_name
339 * @param mixed $default
340 *
341 * @return mixed
342 */
343 public function get( $option_name, $default = null ) {
344 return get_option( self::SETTINGS_PREFIX . $option_name, $default );
345 }
346
347 /**
348 * Get url to settings page
349 *
350 * @return string
351 */
352 public function getLink() {
353 return admin_url( 'admin.php?page=wc-settings&tab=tiered_pricing_table_settings' );
354 }
355 }