PluginProbe
PostNL for WooCommerce / 4.0.1
PostNL for WooCommerce v4.0.1
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 / migration / wcpn-installation-migration-v2-0-0.php

wcpn-installation-migration-v2-0-0.php in PostNL for WooCommerce 4.0.1, at migration/wcpn-installation-migration-v2-0-0.php

77 lines 2.7 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')) {
4 exit;
5 }
6
7 if (class_exists('WCPN_Installation_Migration_v2_0_0')) {
8 return new WCPN_Installation_Migration_v2_0_0();
9 }
10
11 /**
12 * Migrates pre v2.0 settings
13 */
14 class WCPN_Installation_Migration_v2_0_0
15 {
16 /**
17 * Copy old settings if available (pre 2.0 didn't store the version, so technically, this is a new install)
18 */
19 public function __construct()
20 {
21 $old_settings = get_option('wcpostnl_settings');
22
23 // map old key => new_key
24 $general_settings_keys = [
25 'api_key' => 'api_key',
26 'download_display' => 'download_display',
27 'email_tracktrace' => 'email_tracktrace',
28 'myaccount_tracktrace' => 'myaccount_tracktrace',
29 'process' => 'process_directly',
30 'barcode_in_note' => 'barcode_in_note',
31 'keep_consignments' => 'keep_shipments',
32 'error_logging' => 'error_logging',
33 ];
34
35 $general_settings = [];
36 foreach ($general_settings_keys as $old_key => $new_key) {
37 if (! empty($old_settings[$old_key])) {
38 $general_settings[$new_key] = $old_settings[$old_key];
39 }
40 }
41 // auto_complete breaks down into:
42 // order_status_automation & automatic_order_status
43 if (! empty($old_settings['auto_complete'])) {
44 $general_settings['order_status_automation'] = 1;
45 $general_settings['automatic_order_status'] = 'completed';
46 }
47
48 // map old key => new_key
49 $defaults_settings_keys = [
50 'email' => 'connect_email',
51 'telefoon' => 'connect_phone',
52 'handtekening' => 'signature',
53 'retourbgg' => 'return',
54 'kenmerk' => 'label_description',
55 'verzekerd' => 'insured',
56 'verzekerdbedrag' => 'insured_amount',
57 ];
58 $defaults_settings = [];
59 foreach ($defaults_settings_keys as $old_key => $new_key) {
60 if (! empty($old_settings[$old_key])) {
61 $defaults_settings[$new_key] = $old_settings[$old_key];
62 }
63 }
64 // set custom insurance amount
65 if (! empty($defaults_settings['insured']) && (int) $defaults_settings['insured_amount'] > 249) {
66 $defaults_settings['insured_amount'] = 0;
67 $defaults_settings['insured_amount_custom'] = $old_settings['verzekerdbedrag'];
68 }
69
70 // add options
71 update_option('woocommerce_postnl_general_settings', $general_settings);
72 update_option('woocommerce_postnl_export_defaults_settings', $defaults_settings);
73 }
74 }
75
76 new WCPN_Installation_Migration_v2_0_0();
77