PluginProbe
PostNL for WooCommerce / 3.1.7
PostNL for WooCommerce v3.1.7
5.9.12 5.9.11 5.9.10 5.9.9 5.9.8 5.9.7 5.9.6 trunk 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 3.1.4 3.1.5 3.1.6 3.1.7 4.0.0 4.0.1 4.0.2 4.3.2 4.3.3 4.4.0 4.4.1 All 72 releases
woo-postnl / includes / class-wcmp-settings.php

class-wcmp-settings.php in PostNL for WooCommerce 3.1.7, at includes/class-wcmp-settings.php

1,004 lines 40.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( ! defined('ABSPATH')) exit; // Exit if accessed directly
4
5 if ( ! class_exists('WooCommerce_PostNL_Settings')) :
6
7 /**
8 * Create & render settings page
9 */
10 class WooCommerce_PostNL_Settings {
11
12 public $options_page_hook;
13
14 public function __construct() {
15 $this->callbacks = include('class-wcmp-settings-callbacks.php');
16 add_action('admin_menu', array($this, 'menu'));
17 add_filter(
18 'plugin_action_links_' . WooCommerce_PostNL()->plugin_basename, array(
19 $this,
20 'add_settings_link'
21 )
22 );
23
24 add_action('admin_init', array($this, 'general_settings'));
25 add_action('admin_init', array($this, 'export_defaults_settings'));
26 add_action('admin_init', array($this, 'checkout_settings'));
27
28 // notice for WC PostNL Belgium plugin
29 add_action('woocommerce_postnl_before_settings_page', array($this, 'postnl_be_notice'), 10, 1);
30 }
31
32 /**
33 * Add settings item to WooCommerce menu
34 */
35 public function menu() {
36 add_submenu_page(
37 'woocommerce',
38 __('PostNL', 'woocommerce-postnl'),
39 __('PostNL', 'woocommerce-postnl'),
40 'manage_options',
41 'woocommerce_postnl_settings',
42 array($this, 'settings_page')
43 );
44 }
45
46 /**
47 * Add settings link to plugins page
48 */
49 public function add_settings_link($links) {
50 $settings_link = '<a href="admin.php?page=woocommerce_postnl_settings">' . __('Settings', 'woocommerce-postnl') . '</a>';
51 array_push($links, $settings_link);
52
53 return $links;
54 }
55
56 public function settings_page() {
57 $settings_tabs = apply_filters(
58 'woocommerce_postnl_settings_tabs',
59 array(
60 'general' => __('General', 'woocommerce-postnl'),
61 'export_defaults' => __('Default export settings', 'woocommerce-postnl'),
62 'checkout' => __('Checkout', 'woocommerce-postnl'),
63 )
64 );
65
66 $active_tab = isset($_GET['tab']) ? $_GET['tab'] : 'general';
67 ?>
68 <div class="wrap">
69 <h1><?php _e('WooCommerce PostNL Settings', 'woocommerce-postnl'); ?></h1>
70 <h2 class="nav-tab-wrapper">
71 <?php
72 foreach ($settings_tabs as $tab_slug => $tab_title) {
73 printf('<a href="?page=woocommerce_postnl_settings&tab=%1$s" class="nav-tab nav-tab-%1$s %2$s">%3$s</a>', $tab_slug, (($active_tab == $tab_slug) ? 'nav-tab-active' : ''), $tab_title);
74 }
75 ?>
76 </h2>
77
78 <?php do_action('woocommerce_postnl_before_settings_page', $active_tab); ?>
79
80 <form method="post" action="options.php" id="woocommerce-postnl-settings" class="wcmp_shipment_options">
81 <?php
82 do_action('woocommerce_postnl_before_settings', $active_tab);
83 settings_fields('woocommerce_postnl_' . $active_tab . '_settings');
84 do_settings_sections('woocommerce_postnl_' . $active_tab . '_settings');
85 do_action('woocommerce_postnl_after_settings', $active_tab);
86
87 submit_button();
88 ?>
89 </form>
90
91 <?php do_action('woocommerce_postnl_after_settings_page', $active_tab); ?>
92
93 </div>
94 <?php
95 }
96
97 public function postnl_be_notice() {
98 $base_country = WC()->countries->get_base_country();
99
100 // save or check option to hide notice
101 if (isset($_GET['postnl_hide_be_notice'])) {
102 update_option('postnl_hide_be_notice', true);
103 $hide_notice = true;
104 } else {
105 $hide_notice = get_option('postnl_hide_be_notice');
106 }
107
108 // link to hide message when one of the premium extensions is installed
109 if ( ! $hide_notice && $base_country == 'BE') {
110 $postnl_belgium_link = '<a href="https://wordpress.org/plugins/wc-postnl-belgium/" target="blank">WC PostNL Belgium</a>';
111 $text = sprintf(
112 __('It looks like your shop is based in Belgium. This plugin is for PostNL Netherlands. If you are using PostNL Belgium, download the %s plugin instead!', 'woocommerce-postnl'),
113 $postnl_belgium_link
114 );
115 $dismiss_button = sprintf(
116 '<a href="%s" style="display:inline-block; margin-top: 10px;">%s</a>',
117 add_query_arg('postnl_hide_be_notice', 'true'),
118 __('Hide this message', 'woocommerce-postnl')
119 );
120 printf('<div class="notice notice-warning"><p>%s %s</p></div>', $text, $dismiss_button);
121 }
122 }
123
124 /**
125 * Register General settings
126 */
127 public function general_settings() {
128 $option_group = 'woocommerce_postnl_general_settings';
129
130 // Register settings.
131 $option_name = 'woocommerce_postnl_general_settings';
132 register_setting($option_group, $option_name, array($this->callbacks, 'validate'));
133
134 // Create option in wp_options.
135 if (false === get_option($option_name)) {
136 $this->default_settings($option_name);
137 }
138
139 // API section.
140 add_settings_section(
141 'api',
142 __('API settings', 'woocommerce-postnl'),
143 array($this->callbacks, 'section'),
144 $option_group
145 );
146
147 add_settings_field(
148 'api_key',
149 __('Key', 'woocommerce-postnl'),
150 array($this->callbacks, 'text_input'),
151 $option_group,
152 'api',
153 array(
154 'option_name' => $option_name,
155 'id' => 'api_key',
156 'size' => 50,
157 )
158 );
159
160 // General section.
161 add_settings_section(
162 'general',
163 __('General settings', 'woocommerce-postnl'),
164 array($this->callbacks, 'section'),
165 $option_group
166 );
167
168 add_settings_field(
169 'download_display',
170 __('Label display', 'woocommerce-postnl'),
171 array($this->callbacks, 'radio_button'),
172 $option_group,
173 'general',
174 array(
175 'option_name' => $option_name,
176 'id' => 'download_display',
177 'options' => array(
178 'download' => __('Download PDF', 'woocommerce-postnl'),
179 'display' => __('Open the PDF in a new tab', 'woocommerce-postnl'),
180 ),
181 )
182 );
183 add_settings_field(
184 'label_format',
185 __('Label format', 'woocommerce-postnl'),
186 array($this->callbacks, 'radio_button'),
187 $option_group,
188 'general',
189 array(
190 'option_name' => $option_name,
191 'id' => 'label_format',
192 'options' => array(
193 'A4' => __('Standard printer (A4)', 'woocommerce-postnl'),
194 'A6' => __('Label Printer (A6)', 'woocommerce-postnl'),
195 ),
196 )
197 );
198
199 add_settings_field(
200 'print_position_offset',
201 __('Ask for print start position', 'woocommerce-postnl'),
202 array($this->callbacks, 'checkbox'),
203 $option_group,
204 'general',
205 array(
206 'option_name' => $option_name,
207 'id' => 'print_position_offset',
208 'description' => __('This option enables you to continue printing where you left off last time', 'woocommerce-postnl')
209 )
210 );
211
212 add_settings_field(
213 'email_tracktrace',
214 __('Track & Trace in email', 'woocommerce-postnl'),
215 array($this->callbacks, 'checkbox'),
216 $option_group,
217 'general',
218 array(
219 'option_name' => $option_name,
220 'id' => 'email_tracktrace',
221 'description' => __('Add the Track & Trace code to emails to the customer.', 'woocommerce-postnl')
222 )
223 );
224
225 add_settings_field(
226 'myaccount_tracktrace',
227 __('Track & Trace in My Account', 'woocommerce-postnl'),
228 array($this->callbacks, 'checkbox'),
229 $option_group,
230 'general',
231 array(
232 'option_name' => $option_name,
233 'id' => 'myaccount_tracktrace',
234 'description' => __('Show Track & Trace trace code and link in My Account.', 'woocommerce-postnl')
235 )
236 );
237
238 add_settings_field(
239 'process_directly',
240 __('Process shipments directly', 'woocommerce-postnl'),
241 array($this->callbacks, 'checkbox'),
242 $option_group,
243 'general',
244 array(
245 'option_name' => $option_name,
246 'id' => 'process_directly',
247 'description' => __('When you enable this option, shipments will be directly processed when sent to PostNL.', 'woocommerce-postnl')
248 )
249 );
250
251 add_settings_field(
252 'order_status_automation',
253 __('Order status automation', 'woocommerce-postnl'),
254 array($this->callbacks, 'checkbox'),
255 $option_group,
256 'general',
257 array(
258 'option_name' => $option_name,
259 'id' => 'order_status_automation',
260 'description' => __('Automatically set order status to a predefined status after successful export.<br/>Make sure <strong>Process shipments directly</strong> is enabled when you use this option together with the <strong>Track & Trace in email</strong> option, otherwise the Track & Trace code will not be included in the customer email.', 'woocommerce-postnl')
261 )
262 );
263
264 add_settings_field(
265 'automatic_order_status',
266 __('Automatic order status', 'woocommerce-postnl'),
267 array($this->callbacks, 'order_status_select'),
268 $option_group,
269 'general',
270 array(
271 'option_name' => $option_name,
272 'id' => 'automatic_order_status',
273 'class' => 'automatic_order_status',
274 )
275 );
276
277 add_settings_field(
278 'keep_shipments',
279 __('Keep old shipments', 'woocommerce-postnl'),
280 array($this->callbacks, 'checkbox'),
281 $option_group,
282 'general',
283 array(
284 'option_name' => $option_name,
285 'id' => 'keep_shipments',
286 'default' => 0,
287 'description' => __('With this option enabled, data from previous shipments (Track & Trace links) will be kept in the order when you export more than once.', 'woocommerce-postnl')
288 )
289 );
290
291 add_settings_field(
292 'barcode_in_note',
293 __('Place barcode inside note', 'woocommerce-postnl'),
294 array($this->callbacks, 'checkbox'),
295 $option_group,
296 'general',
297 array(
298 'option_name' => $option_name,
299 'id' => 'barcode_in_note',
300 'class' => 'barcode_in_note',
301 'description' => __('Place the barcode inside a note of the order', 'woocommerce-postnl')
302 )
303 );
304
305 add_settings_field(
306 'barcode_in_note_title',
307 __('Title before the barcode', 'woocommerce-postnl'),
308 array($this->callbacks, 'text_input'),
309 $option_group,
310 'general',
311 array(
312 'option_name' => $option_name,
313 'id' => 'barcode_in_note_title',
314 'class' => 'barcode_in_note_title',
315 'default' => 'Tracking code:',
316 'size' => 25,
317 'description' => __('You can change the text before the barcode inside an note', 'woocommerce-postnl'),
318 )
319 );
320
321 // Diagnostics section.
322 add_settings_section(
323 'diagnostics',
324 __('Diagnostic tools', 'woocommerce-postnl'),
325 array($this->callbacks, 'section'),
326 $option_group
327 );
328
329 add_settings_field(
330 'error_logging',
331 __('Log API communication', 'woocommerce-postnl'),
332 array($this->callbacks, 'checkbox'),
333 $option_group,
334 'diagnostics',
335 array(
336 'option_name' => $option_name,
337 'id' => 'error_logging',
338 'description' => '<a href="' . esc_url_raw(admin_url('admin.php?page=wc-status&tab=logs')) . '" target="_blank">' . __('View logs', 'woocommerce-postnl') . '</a> (wc-postnl)',
339 )
340 );
341 }
342
343 /**
344 * Register Export defaults settings
345 */
346 public function export_defaults_settings() {
347 $option_group = 'woocommerce_postnl_export_defaults_settings';
348
349 // Register settings.
350 $option_name = 'woocommerce_postnl_export_defaults_settings';
351 register_setting($option_group, $option_name, array($this->callbacks, 'validate'));
352
353 // Create option in wp_options.
354 if (false === get_option($option_name)) {
355 $this->default_settings($option_name);
356 }
357
358 // API section.
359 add_settings_section(
360 'defaults',
361 __('Default export settings', 'woocommerce-postnl'),
362 array($this->callbacks, 'section'),
363 $option_group
364 );
365
366 if (version_compare(WOOCOMMERCE_VERSION, '2.1', '>=')) {
367 add_settings_field(
368 'shipping_methods_package_types',
369 __('Package types', 'woocommerce-postnl'),
370 array($this->callbacks, 'shipping_methods_package_types'),
371 $option_group,
372 'defaults',
373 array(
374 'option_name' => $option_name,
375 'id' => 'shipping_methods_package_types',
376 'package_types' => WooCommerce_PostNL()->export->get_package_types(),
377 'description' => __('Select one or more shipping methods for each delivery type', 'woocommerce-postnl'),
378 )
379 );
380 } else {
381 add_settings_field(
382 'package_type',
383 __('Shipment type', 'woocommerce-postnl'),
384 array($this->callbacks, 'select'),
385 $option_group,
386 'defaults',
387 array(
388 'option_name' => $option_name,
389 'id' => 'package_type',
390 'default' => (string) WooCommerce_PostNL_Export::PACKAGE,
391 'options' => WooCommerce_PostNL()->export->get_package_types(),
392 )
393 );
394 }
395
396 add_settings_field(
397 'connect_phone',
398 __('Connect customer phone', 'woocommerce-postnl'),
399 array($this->callbacks, 'checkbox'),
400 $option_group,
401 'defaults',
402 array(
403 'option_name' => $option_name,
404 'id' => 'connect_phone',
405 'description' => __("When you connect the customer's phone number, the courier can use this for the delivery of the parcel. This greatly increases the delivery success rate for foreign shipments.", 'woocommerce-postnl')
406 )
407 );
408
409 add_settings_field(
410 'only_recipient',
411 __('Home address only', 'woocommerce-postnl'),
412 array($this->callbacks, 'checkbox'),
413 $option_group,
414 'defaults',
415 array(
416 'option_name' => $option_name,
417 'id' => 'only_recipient',
418 'description' => __("If you don't want the parcel to be delivered at the neighbours, choose this option.", 'woocommerce-postnl')
419 )
420 );
421
422 add_settings_field(
423 'signature',
424 __('Signature on delivery', 'woocommerce-postnl'),
425 array($this->callbacks, 'checkbox'),
426 $option_group,
427 'defaults',
428 array(
429 'option_name' => $option_name,
430 'id' => 'signature',
431 'description' => __('The parcel will be offered at the delivery address. If the recipient is not at home, the parcel will be delivered to the neighbours. In both cases, a signature will be required.', 'woocommerce-postnl')
432 )
433 );
434
435 add_settings_field(
436 'age_check',
437 __('Age check 18+', 'woocommerce-postnl'),
438 array($this->callbacks, 'checkbox'),
439 $option_group,
440 'defaults',
441 array(
442 'option_name' => $option_name,
443 'id' => 'age_check',
444 'description' => __('The age check is intended for parcel shipments for which the recipient must show 18+ by means of a proof of identity. With this shipping option <strong>Signature for receipt</strong> and <strong>Delivery only at recipient</strong> are included. The age 18+ is further excluded from the delivery options morning and evening delivery.', 'woocommerce-postnl')
445 )
446 );
447
448 add_settings_field(
449 'return',
450 __('Return if no answer', 'woocommerce-postnl'),
451 array($this->callbacks, 'checkbox'),
452 $option_group,
453 'defaults',
454 array(
455 'option_name' => $option_name,
456 'id' => 'return',
457 'description' => __('By default, a parcel will be offered twice. After two unsuccessful delivery attempts, the parcel will be available at the nearest pickup point for two weeks. There it can be picked up by the recipient with the note that was left by the courier. If you want to receive the parcel back directly and NOT forward it to the pickup point, enable this option.', 'woocommerce-postnl')
458 )
459 );
460
461 add_settings_field(
462 'insured',
463 __('Insured shipment', 'woocommerce-postnl'),
464 array($this->callbacks, 'checkbox'),
465 $option_group,
466 'defaults',
467 array(
468 'option_name' => $option_name,
469 'id' => 'insured',
470 'description' => __('By default, there is no insurance on the shipments. If you still want to insure the shipment, you can do that. We insure the purchase value of the shipment, with a maximum insured value of &euro; 5.000. Insured parcels always contain the options "Home address only" en "Signature for delivery"', 'woocommerce-postnl'),
471 'class' => 'insured',
472 )
473 );
474
475 add_settings_field(
476 'insured_amount',
477 __('Insured amount', 'woocommerce-postnl'),
478 array($this->callbacks, 'select'),
479 $option_group,
480 'defaults',
481 array(
482 'option_name' => $option_name,
483 'id' => 'insured_amount',
484 'default' => 'standard',
485 'class' => 'insured_amount',
486 'options' => array(
487 '99' => __('Insured up to &euro; 100', 'woocommerce-postnl'),
488 '249' => __('Insured up to &euro; 250', 'woocommerce-postnl'),
489 '499' => __('Insured up to &euro; 500', 'woocommerce-postnl'),
490 '' => __('> &euro; 500 insured', 'woocommerce-postnl'),
491 ),
492 )
493 );
494
495 add_settings_field(
496 'insured_amount_custom',
497 __('Insured amount (in euro)', 'woocommerce-postnl'),
498 array($this->callbacks, 'text_input'),
499 $option_group,
500 'defaults',
501 array(
502 'option_name' => $option_name,
503 'id' => 'insured_amount_custom',
504 'size' => '5',
505 'class' => 'insured_amount',
506 )
507 );
508
509 add_settings_field(
510 'label_description',
511 __('Label description', 'woocommerce-postnl'),
512 array($this->callbacks, 'text_input'),
513 $option_group,
514 'defaults',
515 array(
516 'option_name' => $option_name,
517 'id' => 'label_description',
518 'size' => '25',
519 'description' => __("With this option, you can add a description to the shipment. This will be printed on the top left of the label, and you can use this to search or sort shipments in your backoffice. Use <strong>[ORDER_NR]</strong> to include the order number, <strong>[DELIVERY_DATE]</strong> to include the delivery date.", 'woocommerce-postnl'),
520 )
521 );
522
523 add_settings_field(
524 'empty_parcel_weight',
525 __('Empty parcel weight (grams)', 'woocommerce-postnl'),
526 array($this->callbacks, 'text_input'),
527 $option_group,
528 'defaults',
529 array(
530 'option_name' => $option_name,
531 'id' => 'empty_parcel_weight',
532 'size' => '5',
533 'description' => __('Default weight of your empty parcel, rounded to grams.', 'woocommerce-postnl'),
534 )
535 );
536
537 // World Shipments section.
538 add_settings_section(
539 'world_shipments',
540 __('World Shipments', 'woocommerce-postnl'),
541 array($this->callbacks, 'section'),
542 $option_group
543 );
544
545 add_settings_field(
546 'hs_code',
547 __('Default HS Code', 'woocommerce-postnl'),
548 array($this->callbacks, 'text_input'),
549 $option_group,
550 'world_shipments',
551 array(
552 'option_name' => $option_name,
553 'id' => 'hs_code',
554 'size' => '5',
555 'description' => sprintf(__('HS Codes are used for PostNL world shipments, you can find the appropriate code on the %ssite of the Dutch Customs%s.', 'woocommerce-postnl'), '<a href="http://tarief.douane.nl/arctictariff-public-web/#!/home" target="_blank">', '</a>')
556 )
557 );
558 add_settings_field(
559 'package_contents',
560 __('Customs shipment type', 'woocommerce-postnl'),
561 array($this->callbacks, 'select'),
562 $option_group,
563 'world_shipments',
564 array(
565 'option_name' => $option_name,
566 'id' => 'package_contents',
567 'options' => array(
568 1 => __('Commercial goods', 'woocommerce-postnl'),
569 2 => __('Commercial samples', 'woocommerce-postnl'),
570 3 => __('Documents', 'woocommerce-postnl'),
571 4 => __('Gifts', 'woocommerce-postnl'),
572 5 => __('Return shipment', 'woocommerce-postnl'),
573 ),
574 )
575 );
576 }
577
578 /**
579 * Register Checkout settings
580 */
581 public function checkout_settings() {
582 $option_group = 'woocommerce_postnl_checkout_settings';
583
584 // Register settings.
585 $option_name = 'woocommerce_postnl_checkout_settings';
586 register_setting($option_group, $option_name, array($this->callbacks, 'validate'));
587
588 // Create option in wp_options.
589 if (false === get_option($option_name)) {
590 $this->default_settings($option_name);
591 }
592
593 add_settings_field(
594 'use_split_address_fields',
595 __('PostNL address fields', 'woocommerce-postnl'),
596 array($this->callbacks, 'checkbox' ),
597 $option_group,
598 'processing_parameters',
599 array(
600 'option_name' => $option_name,
601 'id' => 'use_split_address_fields',
602 'class' => 'use_split_address_fields',
603 'description' => __('When enabled the checkout will use the PostNL address fields. This means there will be three separate fields for street name, number and suffix. Want to use the WooCommerce default fields? Leave this option unchecked.', 'woocommerce-postnl'),
604 )
605 );
606
607 add_settings_field(
608 'postnl_checkout',
609 __('Enable PostNL delivery options', 'woocommerce-postnl'),
610 array($this->callbacks, 'checkbox'),
611 $option_group,
612 'processing_parameters',
613 array(
614 'option_name' => $option_name,
615 'id' => 'postnl_checkout',
616 )
617 );
618
619 add_settings_field(
620 'checkout_display',
621 __('Display for', 'woocommerce-postnl'),
622 array($this->callbacks, 'select'),
623 $option_group,
624 'processing_parameters',
625 array(
626 'option_name' => $option_name,
627 'id' => 'checkout_display',
628 'options' => array(
629 'selected_methods' => __('Shipping methods associated with Parcels', 'woocommerce-postnl'),
630 'all_methods' => __('All shipping methods', 'woocommerce-postnl'),
631 ),
632 'description' => __('To associate specific shipping methods with parcels, see the Default export settings tab. Note that the delivery options will be automatically hidden for foreign addresses, regardless of this setting.', 'woocommerce-postnl'),
633 )
634 );
635
636 // Checkout options section.
637 add_settings_section(
638 'processing_parameters', __('Shipment processing parameters', 'woocommerce-postnl'), array(
639 $this->callbacks,
640 'section'
641 ), $option_group
642 );
643
644 // Place of the checkout
645 add_settings_field(
646 'checkout_place', __('Checkout place', 'woocommerce-postnl'), array(
647 $this->callbacks,
648 'select'
649 ), $option_group, 'processing_parameters', array(
650 'option_name' => $option_name,
651 'id' => 'checkout_position',
652 'options' => array(
653 'woocommerce_after_checkout_billing_form' => __('Show checkout options after billing details', 'woocommerce-postnl'),
654 'woocommerce_after_checkout_shipping_form' => __('Show checkout options after shipping details', 'woocommerce-postnl'),
655 'woocommerce_after_order_notes' => __('Show checkout options after notes', 'woocommerce-postnl'),
656 ),
657 'description' => __('You can change the place of the checkout options on the checkout page. By default it will be placed after shipping details.', 'woocommerce-postnl'),
658 )
659 );
660
661 $days_of_the_week = array(
662 '0' => __('Sunday', 'woocommerce-postnl'),
663 '1' => __('Monday', 'woocommerce-postnl'),
664 '2' => __('Tuesday', 'woocommerce-postnl'),
665 '3' => __('Wednesday', 'woocommerce-postnl'),
666 '4' => __('Thursday', 'woocommerce-postnl'),
667 '5' => __('Friday', 'woocommerce-postnl'),
668 '6' => __('Saturday', 'woocommerce-postnl'),
669 );
670
671 add_settings_field(
672 'dropoff_days', __('Drop-off days', 'woocommerce-postnl'), array(
673 $this->callbacks,
674 'enhanced_select'
675 ), $option_group, 'processing_parameters', array(
676 'option_name' => $option_name,
677 'id' => 'dropoff_days',
678 'options' => $days_of_the_week,
679 'description' => __('Days of the week on which you hand over parcels to PostNL', 'woocommerce-postnl'),
680 )
681 );
682
683 add_settings_field(
684 'cutoff_time', __('Cut-off time', 'woocommerce-postnl'), array(
685 $this->callbacks,
686 'text_input'
687 ), $option_group, 'processing_parameters', array(
688 'option_name' => $option_name,
689 'id' => 'cutoff_time',
690 'type' => 'text',
691 'size' => '5',
692 'description' => __('Time at which you stop processing orders for the day (format: hh:mm)', 'woocommerce-postnl'),
693 )
694 );
695
696 add_settings_field(
697 'dropoff_delay', __('Drop-off delay', 'woocommerce-postnl'), array(
698 $this->callbacks,
699 'text_input'
700 ), $option_group, 'processing_parameters', array(
701 'option_name' => $option_name,
702 'id' => 'dropoff_delay',
703 'type' => 'text',
704 'size' => '5',
705 'description' => __('Number of days you need to process an order.', 'woocommerce-postnl'),
706 )
707 );
708
709 add_settings_field(
710 'deliverydays_window', __('Delivery days window', 'woocommerce-postnl'), array(
711 $this->callbacks,
712 'text_input'
713 ), $option_group, 'processing_parameters', array(
714 'option_name' => $option_name,
715 'id' => 'deliverydays_window',
716 'type' => 'text',
717 'size' => '5',
718 'description' => __('Amount of days a customer can postpone delivery. Default is 0 days with a maximum of 14.', 'woocommerce-postnl'),
719 )
720 );
721
722 // Delivery options section.
723 add_settings_section(
724 'delivery_options', __('Delivery options', 'woocommerce-postnl'), array(
725 $this->callbacks,
726 'section'
727 ), $option_group
728 );
729
730 add_settings_field(
731 'header_delivery_options_title', __('Delivery options title', 'woocommerce-postnl'), array(
732 $this->callbacks,
733 'text_input'
734 ), $option_group, 'delivery_options', array(
735 'option_name' => $option_name,
736 'id' => 'header_delivery_options_title',
737 'size' => '53',
738 'title' => 'Delivery options title',
739 'current' => self::get_checkout_setting_title('header_delivery_options_title'),
740 'description' => __('You can place a delivery title above the PostNL options. When there is no title, it will not be visible.', 'woocommerce-postnl'),
741 )
742 );
743
744 add_settings_field(
745 'at_home_delivery', __('Home delivery title', 'woocommerce-postnl'), array(
746 $this->callbacks,
747 'text_input'
748 ), $option_group, 'delivery_options', array(
749 'option_name' => $option_name,
750 'id' => 'at_home_delivery_title',
751 'size' => '53',
752 'title' => 'Delivered at home or at work',
753 'current' => self::get_checkout_setting_title('at_home_delivery_title'),
754 )
755 );
756
757 add_settings_field(
758 'standard', __('Standard delivery title', 'woocommerce-postnl'), array(
759 $this->callbacks,
760 'text_input'
761 ), $option_group, 'delivery_options', array(
762 'option_name' => $option_name,
763 'id' => 'standard_title',
764 'size' => '53',
765 'title' => 'Standard delivery',
766 'current' => self::get_checkout_setting_title('standard_title'),
767 'description' => __('When there is no title, the delivery time will automatically be visible.', 'woocommerce-postnl'),
768 )
769 );
770
771 add_settings_field(
772 'morning', __('Morning delivery', 'woocommerce-postnl'), array(
773 $this->callbacks,
774 'delivery_option_enable'
775 ), $option_group, 'delivery_options', array(
776 'has_title' => true,
777 'has_price' => true,
778 'option_name' => $option_name,
779 'id' => 'morning',
780 'title' => 'Morning delivery',
781 'current' => self::get_checkout_setting_title('morning_title'),
782 'size' => 30,
783 'option_description' => __('When there is no title, the delivery time will automatically be visible.', 'woocommerce-postnl'),
784 )
785 );
786
787 add_settings_field(
788 'evening', __('Evening delivery', 'woocommerce-postnl'), array(
789 $this->callbacks,
790 'delivery_option_enable'
791 ), $option_group, 'delivery_options', array(
792 'has_title' => true,
793 'has_price' => true,
794 'option_name' => $option_name,
795 'id' => 'evening',
796 'title' => 'Evening delivery',
797 'current' => self::get_checkout_setting_title('evening_title'),
798 'size' => 30,
799 'option_description' => __('When there is no title, the delivery time will automatically be visible.', 'woocommerce-postnl'),
800 )
801 );
802
803 add_settings_field(
804 'only_recipient', __('Home address only', 'woocommerce-postnl'), array(
805 $this->callbacks,
806 'delivery_option_enable'
807 ), $option_group, 'delivery_options', array(
808 'has_title' => true,
809 'has_price' => true,
810 'option_name' => $option_name,
811 'id' => 'only_recipient',
812 'title' => 'Home address only',
813 'current' => self::get_checkout_setting_title('at_home_delivery_title'),
814 'size' => 30,
815 )
816 );
817
818 add_settings_field(
819 'signature', __('Signature on delivery', 'woocommerce-postnl'), array(
820 $this->callbacks,
821 'delivery_option_enable'
822 ), $option_group, 'delivery_options', array(
823 'has_title' => true,
824 'has_price' => true,
825 'option_name' => $option_name,
826 'id' => 'signature',
827 'title' => 'Signature on delivery',
828 'current' => self::get_checkout_setting_title('signature_title'),
829 'size' => 30,
830 )
831 );
832
833 add_settings_field(
834 'pickup', __('PostNL pickup', 'woocommerce-postnl'), array(
835 $this->callbacks,
836 'delivery_option_enable'
837 ), $option_group, 'delivery_options', array(
838 'has_title' => true,
839 'has_price' => true,
840 'option_name' => $option_name,
841 'id' => 'pickup',
842 'class' => 'pickup',
843 'title' => 'Pickup',
844 'current' => self::get_checkout_setting_title('pickup_title'),
845 'size' => 30,
846 )
847 );
848
849 add_settings_field(
850 'pickup_express', __('Early PostNL pickup', 'woocommerce-postnl'), array(
851 $this->callbacks,
852 'delivery_option_enable'
853 ), $option_group, 'delivery_options', array(
854 'has_title' => false,
855 'has_price' => true,
856 'option_name' => $option_name,
857 'id' => 'pickup_express',
858 'class' => 'pickup_express',
859 'title' => 'Pickup express',
860 'current' => __('Early PostNL pickup', 'woocommerce-postnl'),
861 'size' => 30,
862 )
863 );
864
865 add_settings_field(
866 'saturday_cutoff', __('Enable monday delivery', 'woocommerce-postnl'), array(
867 $this->callbacks,
868 'delivery_option_enable'
869 ), $option_group, 'delivery_options', array(
870 'has_title' => false,
871 'has_price' => false,
872 'has_cutoff_time' => true,
873 'option_name' => $option_name,
874 'id' => 'saturday_cutoff',
875 'size' => 30,
876 'option_description' => sprintf(__('<strong>Note: Your drop-off days must include Saturday and cut-off time on Saturday must be before 15:00 (14:30 recommended).</strong>', 'woocommerce-postnl')),
877 )
878 );
879
880 // Belgium delivery options
881 add_settings_section(
882 'Belgium_delivery_options', __('Belgium delivery options', 'woocommerce-postnl'), array(
883 $this->callbacks,
884 'section'
885 ), $option_group
886 );
887
888 add_settings_field(
889 'belgium_at_home_delivery', __('Belgium home delivery title', 'woocommerce-postnl'), array(
890 $this->callbacks,
891 'text_input'
892 ), $option_group, 'Belgium_delivery_options', array(
893 'option_name' => $option_name,
894 'id' => 'belgium_at_home_delivery_title',
895 'size' => '53',
896 'title' => 'Delivery',
897 'current' => self::get_checkout_setting_title('belgium_at_home_delivery_title'),
898 )
899 );
900
901 add_settings_field(
902 'BEstandard', __('Belgium standard delivery title', 'woocommerce-postnl'), array(
903 $this->callbacks,
904 'text_input'
905 ), $option_group, 'Belgium_delivery_options', array(
906 'option_name' => $option_name,
907 'id' => 'belgium_standard_title',
908 'size' => '53',
909 'title' => 'Standard delivery',
910 'current' => self::get_checkout_setting_title('belgium_standard_title'),
911 'description' => __('When there is no title, the delivery time will automatically be visible.', 'woocommerce-postnl'),
912 )
913 );
914
915 // Customizations section
916 add_settings_section(
917 'customizations', __('Customizations', 'woocommerce-postnl'), array(
918 $this->callbacks,
919 'section'
920 ), $option_group
921 );
922
923 add_settings_field(
924 'custom_css', __('Custom styles', 'woocommerce-postnl'), array(
925 $this->callbacks,
926 'textarea'
927 ), $option_group, 'customizations', array(
928 'option_name' => $option_name,
929 'id' => 'custom_css',
930 'width' => '80',
931 'height' => '8',
932 )
933 );
934 }
935
936 /**
937 * Set default settings.
938 * @return void.
939 */
940 public function default_settings($option) {
941 switch($option) {
942 case 'woocommerce_postnl_general_settings':
943 $default = array(
944 'download_display' => 'download',
945 'label_format' => 'A4',
946 );
947 break;
948 case 'woocommerce_postnl_checkout_settings':
949 $default = self::get_checkout_settings();
950 break;
951 case 'woocommerce_postnl_export_defaults_settings':
952 default:
953 $default = array();
954 break;
955 }
956
957 if (false === get_option($option)) {
958 add_option($option, $default);
959 } else {
960 update_option($option, $default);
961 }
962 }
963
964 /**
965 * @param $key
966 *
967 * @return string
968 */
969 public static function get_checkout_setting_title($key) {
970 $checkout_settings = self::get_checkout_settings();
971 $setting = $checkout_settings[$key];
972
973 return __($setting, 'woocommerce-postnl');
974 }
975
976 /**
977 * @return array
978 */
979 public static function get_checkout_settings() {
980 return array(
981 'pickup_enabled' => '0',
982 'dropoff_days' => array(1, 2, 3, 4, 5),
983 'dropoff_delay' => '0',
984 'deliverydays_window' => '1',
985 'checkout_position' => 'woocommerce_after_checkout_billing_form',
986 'header_delivery_options_title' => 'Delivery options',
987 'at_home_delivery_title' => 'Delivered at home or at work',
988 'standard_title' => 'Standard delivery',
989 'morning_title' => 'Morning delivery',
990 'evening_title' => 'Evening delivery',
991 'only_recipient_title' => 'Home address only',
992 'signature_title' => 'Signature on delivery',
993 'pickup_title' => 'PostNL Pickup',
994 'belgium_at_home_delivery_title' => 'Delivery',
995 'belgium_standard_title' => 'Standard delivery',
996 'use_split_address_fields' => '0',
997 );
998 }
999 }
1000
1001 endif; // class_exists
1002
1003 return new WooCommerce_PostNL_Settings();
1004