PluginProbe
Tiered Pricing Table for WooCommerce / 2.0.2
Tiered Pricing Table for WooCommerce v2.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 2.3.4 All 90 releases
tier-pricing-table / src / Settings / Settings.php

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

314 lines 10.9 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 what and where tiered pricing table will be displayed at product page',
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 ],
76 [
77 'title' => __( 'Tooltip icon color', 'tier-pricing-table' ),
78 'id' => self::SETTINGS_PREFIX . 'tooltip_color',
79 'type' => 'color',
80 'default' => '#cc99c2',
81 'desc' => __( 'Color of icon', 'tier-pricing-table' ),
82 'desc_tip' => true,
83 ],
84 [
85 'title' => __( 'Tooltip icon size (px)', 'tier-pricing-table' ),
86 'id' => self::SETTINGS_PREFIX . 'tooltip_size',
87 'type' => 'number',
88 'default' => '15',
89 'desc' => __( 'Size of icon', 'tier-pricing-table' ),
90 'desc_tip' => true,
91 ],
92 [
93 'title' => __( 'Tooltip border', 'tier-pricing-table' ),
94 'id' => self::SETTINGS_PREFIX . 'tooltip_border',
95 'type' => 'checkbox',
96 'default' => 'yes',
97 'desc' => __( 'Enable tooltip border', 'tier-pricing-table' ),
98 ],
99 [
100 'title' => __( 'Table title', 'tier-pricing-table' ),
101 'id' => self::SETTINGS_PREFIX . 'table_title',
102 'type' => 'text',
103 'default' => '',
104 'desc' => __( 'The name is being displayed above the table', 'tier-pricing-table' ),
105 'desc_tip' => true,
106 ],
107 [
108 'title' => __( 'Table position', 'tier-pricing-table' ),
109 'id' => self::SETTINGS_PREFIX . 'position_hook',
110 'type' => 'select',
111 'options' => [
112 'woocommerce_before_add_to_cart_button' => __( 'Above buy button', 'tier-pricing-table' ),
113 'woocommerce_after_add_to_cart_button' => __( 'Below buy button', 'tier-pricing-table' ),
114 'woocommerce_single_product_summary' => __( 'Above product title', 'tier-pricing-table' ),
115 'woocommerce_before_single_product_summary' => __( 'Before product summary', 'tier-pricing-table' ),
116 'woocommerce_after_single_product_summary' => __( 'After product summary', 'tier-pricing-table' ),
117 ],
118 'desc' => __( 'Where to display the table', 'tier-pricing-table' ),
119 'desc_tip' => true,
120 ],
121 [
122 'title' => __( 'Active price background color', 'tier-pricing-table' ),
123 'id' => self::SETTINGS_PREFIX . 'selected_quantity_color',
124 'type' => 'color',
125 'css' => 'width:6em;',
126 'default' => '#cc99c2',
127 'desc' => __( 'Active tiered price background color', 'tier-pricing-table' ),
128 'desc_tip' => true,
129 ],
130 [
131 'title' => __( 'Quantity text', 'tier-pricing-table' ),
132 'id' => self::SETTINGS_PREFIX . 'head_quantity_text',
133 'type' => 'text',
134 'default' => __( 'Quantity', 'tier-pricing-table' ),
135 'desc' => __( 'Name of quantity column', 'tier-pricing-table' ),
136 'desc_tip' => true,
137 ],
138 [
139 'title' => __( 'Price text', 'tier-pricing-table' ),
140 'id' => self::SETTINGS_PREFIX . 'head_price_text',
141 'type' => 'text',
142 'default' => __( 'Price', 'tier-pricing-table' ),
143 'desc' => __( 'Name of price column', 'tier-pricing-table' ),
144 'desc_tip' => true,
145 ],
146 [
147 'title' => __( 'CSS class', 'tier-pricing-table' ),
148 'id' => self::SETTINGS_PREFIX . 'table_css_class',
149 'type' => 'text',
150 'default' => '',
151 'desc' => __( 'You can add your own css styles for this class. The class will be added to the table',
152 'tier-pricing-table' ),
153 'desc_tip' => true,
154 ],
155 [
156 'type' => 'sectionend',
157 'id' => self::SETTINGS_PREFIX . 'options'
158 ],
159 // Premium Here
160 [
161 'title' => __( 'Advanced settings', 'tier-pricing-table' ),
162 'id' => self::SETTINGS_PREFIX . 'premium_options',
163 'type' => 'title',
164 'custom_attributes' => [ 'data-tiered-pricing-premium-setting' => true ]
165 ],
166 [
167 'title' => __( 'Show tiered price in cart as discount', 'tier-pricing-table' ),
168 'id' => self::SETTINGS_PREFIX . 'show_discount_in_cart',
169 'desc' => __( 'Example:', 'tier-pricing-table' ) . ' <del>10$</del> 8$',
170 'type' => 'checkbox',
171 'default' => 'yes',
172 'desc_tip' => true,
173 'custom_attributes' => [ 'data-tiered-pricing-premium-setting' => 'yes' ]
174 ],
175 [
176 'title' => __( 'Use Tiered Price at Catalog', 'tier-pricing-table' ),
177 'id' => self::SETTINGS_PREFIX . 'tiered_price_at_catalog',
178 'type' => 'checkbox',
179 'default' => 'yes',
180 'desc' => __( 'Enable\Disable showing tiered price at catalog', 'tier-pricing-table' ),
181 'desc_tip' => true,
182 'custom_attributes' => [ 'data-tiered-pricing-premium-setting' => true ]
183 ],
184 [
185 'title' => __( 'Display type as', 'tier-pricing-table' ),
186 'id' => self::SETTINGS_PREFIX . 'tiered_price_at_catalog_type',
187 'type' => 'select',
188 'options' => [
189 'range' => __( 'Range (from lowest to highest)', 'tier-pricing-table' ),
190 'lowest' => __( 'Lowest price', 'tier-pricing-table' ),
191 ],
192 'desc' => __( 'How to display price at catalog', 'tier-pricing-table' ),
193 'desc_tip' => true,
194 'custom_attributes' => [ 'data-tiered-pricing-premium-setting' => true ]
195 ],
196 [
197 'title' => __( 'Lowest price prefix', 'tier-pricing-table' ),
198 'id' => self::SETTINGS_PREFIX . 'lowest_prefix',
199 'type' => 'text',
200 'default' => __( 'From', 'tier-pricing-table' ),
201 'desc' => __( 'Prefix before lowest product price at catalog. Example: <b>From 10$</b>',
202 'tier-pricing-table' ),
203 'desc_tip' => true,
204 'custom_attributes' => [ 'data-tiered-pricing-premium-setting' => true ]
205 ],
206 [
207 'title' => __( 'Show discount column for percentage table', 'tier-pricing-table' ),
208 'id' => self::SETTINGS_PREFIX . 'show_discount_column',
209 'type' => 'checkbox',
210 'default' => 'yes',
211 'custom_attributes' => [ 'data-tiered-pricing-premium-setting' => true ]
212 ],
213 [
214 'title' => __( 'Discount text', 'tier-pricing-table' ),
215 'id' => self::SETTINGS_PREFIX . 'head_discount_text',
216 'type' => 'text',
217 'default' => __( 'Discount (%)', 'tier-pricing-table' ),
218 'desc' => __( 'Name of discount column', 'tier-pricing-table' ),
219 'desc_tip' => true,
220 'custom_attributes' => [ 'data-tiered-pricing-premium-setting' => true ]
221 ],
222 [
223 'type' => 'sectionend',
224 'id' => self::SETTINGS_PREFIX . 'premium_options'
225 ],
226 );
227 }
228
229 /**
230 * Register hooks
231 */
232 public function hooks() {
233 add_action( 'init', [ $this, 'initSettings' ] );
234
235 add_filter( 'woocommerce_settings_tabs_' . self::SETTINGS_PAGE, [ $this, 'addTieredPricingTableSettings' ] );
236 add_filter( 'woocommerce_settings_tabs_array', [ $this, 'addSettingsTab' ], 50 );
237 add_action( 'woocommerce_update_options_' . self::SETTINGS_PAGE, [ $this, 'updateSettings' ] );
238 }
239
240 /**
241 * Add own settings tab
242 *
243 * @param array $settings_tabs
244 *
245 * @return mixed
246 */
247 public static function addSettingsTab( $settings_tabs ) {
248
249 $settings_tabs[ self::SETTINGS_PAGE ] = __( 'Tiered Pricing', 'tier-pricing-table' );
250
251 return $settings_tabs;
252 }
253
254 /**
255 * Add settings to WooCommerce
256 */
257 public function addTieredPricingTableSettings() {
258
259 wp_enqueue_script( 'quantity-table-settings-js', $this->fileManager->locateAsset( 'admin/settings.js' ) );
260
261 return woocommerce_admin_fields( $this->settings );
262 }
263
264 /**
265 * Get all settings
266 *
267 * @return array
268 */
269 public function getAll() {
270 return [
271 'display' => $this->get( 'display', 'yes' ),
272 'position_hook' => $this->get( 'position_hook', 'woocommerce_after_add_to_cart_button' ),
273 'head_quantity_text' => $this->get( 'head_quantity_text',
274 __( 'Quantity', 'tier-pricing-table' ) ),
275 'head_price_text' => $this->get( 'head_price_text', __( 'Price', 'tier-pricing-table' ) ),
276 'display_type' => $this->get( 'display_type', 'table' ),
277 'selected_quantity_color' => $this->get( 'selected_quantity_color', '#cc99c2' ),
278 'table_title' => $this->get( 'table_title', '' ),
279 'table_css_class' => $this->get( 'table_css_class', '#fff' ),
280 'tooltip_size' => $this->get( 'tooltip_size', 15 ),
281 'tooltip_border' => $this->get( 'tooltip_border', 'yes' ),
282
283 /* Premium */
284 'show_discount_in_cart' => $this->get( 'show_discount_in_cart', 'yes' ),
285 'tiered_price_at_catalog' => $this->get( 'tiered_price_at_catalog', 'yes' ),
286 'tiered_price_at_catalog_type' => $this->get( 'tiered_price_at_catalog_type', 'yes' ),
287 'lowest_prefix' => $this->get( 'lowest_prefix', 'yes' ),
288 'show_discount_column' => $this->get( 'show_discount_column', 'yes' ),
289 'head_discount_text' => $this->get( 'head_discount_text',
290 __( 'Discount (%)', 'tier-pricing-table' ) ),
291 ];
292 }
293
294 /**
295 * Get setting by name
296 *
297 * @param string $option_name
298 * @param mixed $default
299 *
300 * @return mixed
301 */
302 public function get( $option_name, $default = null ) {
303 return get_option( self::SETTINGS_PREFIX . $option_name, $default );
304 }
305
306 /**
307 * Get url to settings page
308 *
309 * @return string
310 */
311 public function getLink() {
312 return admin_url( 'admin.php?page=wc-settings&tab=tiered_pricing_table_settings' );
313 }
314 }