/includes/class-wcmp-settings.php

  1. <?php 
  2. /** 
  3. * Create & render settings page 
  4. */ 
  5.  
  6. if ( ! defined( 'ABSPATH' ) ) { 
  7. exit; // Exit if accessed directly 
  8.  
  9. if ( !class_exists( 'WooCommerce_MyParcel_Settings' ) ) : 
  10.  
  11. class WooCommerce_MyParcel_Settings { 
  12.  
  13. public $options_page_hook; 
  14.  
  15. public function __construct() { 
  16. $this->callbacks = include( 'class-wcmp-settings-callbacks.php' ); 
  17. add_action( 'admin_menu', array( $this, 'menu' ) ); 
  18. add_filter( 'plugin_action_links_'.WooCommerce_MyParcel()->plugin_basename, array( $this, 'add_settings_link' ) ); 
  19.  
  20. add_action( 'admin_init', array( $this, 'general_settings' ) ); 
  21. add_action( 'admin_init', array( $this, 'export_defaults_settings' ) ); 
  22. add_action( 'admin_init', array( $this, 'checkout_settings' ) ); 
  23.  
  24. // notice for WC MyParcel Belgium plugin 
  25. add_action( 'woocommerce_myparcel_before_settings_page', array( $this, 'myparcel_be_notice'), 10, 1 ); 
  26.  
  27. /** 
  28. * Add settings item to WooCommerce menu 
  29. */ 
  30. public function menu() { 
  31. add_submenu_page( 
  32. 'woocommerce',  
  33. __( 'MyParcel', 'woocommerce-myparcel' ),  
  34. __( 'MyParcel', 'woocommerce-myparcel' ),  
  35. 'manage_options',  
  36. 'woocommerce_myparcel_settings',  
  37. array( $this, 'settings_page' ) 
  38. );  
  39.  
  40. /** 
  41. * Add settings link to plugins page 
  42. */ 
  43. public function add_settings_link( $links ) { 
  44. $settings_link = '<a href="admin.php?page=woocommerce_myparcel_settings">'. __( 'Settings', 'woocommerce-myparcel' ) . '</a>'; 
  45. array_push( $links, $settings_link ); 
  46. return $links; 
  47.  
  48. public function settings_page() { 
  49. $settings_tabs = apply_filters( 'woocommerce_myparcel_settings_tabs', array ( 
  50. 'general' => __( 'General', 'woocommerce-myparcel' ),  
  51. 'export_defaults' => __( 'Default export settings', 'woocommerce-myparcel' ),  
  52. 'checkout' => __( 'Checkout', 'woocommerce-myparcel' ),  
  53. ); 
  54.  
  55. $active_tab = isset( $_GET[ 'tab' ] ) ? $_GET[ 'tab' ] : 'general'; 
  56. ?> 
  57. <div class="wrap"> 
  58. <h1><?php _e( 'WooCommerce MyParcel Settings', 'woocommerce-myparcel' ); ?></h1> 
  59. <h2 class="nav-tab-wrapper"> 
  60. <?php 
  61. foreach ($settings_tabs as $tab_slug => $tab_title ) { 
  62. printf('<a href="?page=woocommerce_myparcel_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); 
  63. ?> 
  64. </h2> 
  65.  
  66. <?php do_action( 'woocommerce_myparcel_before_settings_page', $active_tab ); ?> 
  67.  
  68. <form method="post" action="options.php" id="woocommerce-myparcel-settings" class="wcmp_shipment_options"> 
  69. <?php 
  70. do_action( 'woocommerce_myparcel_before_settings', $active_tab ); 
  71. settings_fields( 'woocommerce_myparcel_'.$active_tab.'_settings' ); 
  72. do_settings_sections( 'woocommerce_myparcel_'.$active_tab.'_settings' ); 
  73. do_action( 'woocommerce_myparcel_after_settings', $active_tab ); 
  74.  
  75. submit_button(); 
  76. ?> 
  77. </form> 
  78.  
  79. <?php do_action( 'woocommerce_myparcel_after_settings_page', $active_tab ); ?> 
  80.  
  81. </div> 
  82. <?php 
  83.  
  84. public function myparcel_be_notice( $active_tab ) { 
  85. $base_country = WC()->countries->get_base_country(); 
  86.  
  87. // save or check option to hide notice 
  88. if ( isset( $_GET['myparcel_hide_be_notice'] ) ) { 
  89. update_option( 'myparcel_hide_be_notice', true ); 
  90. $hide_notice = true; 
  91. } else { 
  92. $hide_notice = get_option( 'myparcel_hide_be_notice' ); 
  93.  
  94. // link to hide message when one of the premium extensions is installed 
  95. if ( !$hide_notice && $base_country == 'BE' ) { 
  96. $myparcel_belgium_link = '<a href="https://wordpress.org/plugins/wc-myparcel-belgium/" target="blank">WC MyParcel Belgium</a>'; 
  97. $text = sprintf(__( 'It looks like your shop is based in Belgium. This plugin is for MyParcel Netherlands. If you are using MyParcel Belgium, download the %s plugin instead!', 'woocommerce-myparcel' ), $myparcel_belgium_link); 
  98. $dismiss_button = sprintf('<a href="%s" style="display:inline-block; margin-top: 10px;">%s</a>', add_query_arg( 'myparcel_hide_be_notice', 'true' ), __( 'Hide this message', 'woocommerce-myparcel' ) ); 
  99. printf('<div class="notice notice-warning"><p>%s %s</p></div>', $text, $dismiss_button); 
  100.  
  101. /** 
  102. * Register General settings 
  103. */ 
  104. public function general_settings() { 
  105. $option_group = 'woocommerce_myparcel_general_settings'; 
  106.  
  107. // Register settings. 
  108. $option_name = 'woocommerce_myparcel_general_settings'; 
  109. register_setting( $option_group, $option_name, array( $this->callbacks, 'validate' ) ); 
  110.  
  111. // Create option in wp_options. 
  112. if ( false === get_option( $option_name ) ) { 
  113. $this->default_settings( $option_name ); 
  114.  
  115. // API section. 
  116. add_settings_section( 
  117. 'api',  
  118. __( 'API settings', 'woocommerce-myparcel' ),  
  119. array( $this->callbacks, 'section' ),  
  120. $option_group 
  121. ); 
  122.  
  123. // add_settings_field( 
  124. // 'api_username',  
  125. // __( 'Username', 'woocommerce-myparcel' ),  
  126. // array( $this->callbacks, 'text_input' ),  
  127. // $option_group,  
  128. // 'api',  
  129. // array( 
  130. // 'option_name' => $option_name,  
  131. // 'id' => 'api_username',  
  132. // 'size' => 50,  
  133. // ) 
  134. // )
  135.  
  136. add_settings_field( 
  137. 'api_key',  
  138. __( 'Key', 'woocommerce-myparcel' ),  
  139. array( $this->callbacks, 'text_input' ),  
  140. $option_group,  
  141. 'api',  
  142. array( 
  143. 'option_name' => $option_name,  
  144. 'id' => 'api_key',  
  145. 'size' => 50,  
  146. ); 
  147.  
  148. // General section. 
  149. add_settings_section( 
  150. 'general',  
  151. __( 'General settings', 'woocommerce-myparcel' ),  
  152. array( $this->callbacks, 'section' ),  
  153. $option_group 
  154. ); 
  155.  
  156. add_settings_field( 
  157. 'download_display',  
  158. __( 'Label display', 'woocommerce-myparcel' ),  
  159. array( $this->callbacks, 'radio_button' ),  
  160. $option_group,  
  161. 'general',  
  162. array( 
  163. 'option_name' => $option_name,  
  164. 'id' => 'download_display',  
  165. 'options' => array( 
  166. 'download' => __( 'Download PDF' , 'woocommerce-myparcel' ),  
  167. 'display' => __( 'Open de PDF in a new tab' , 'woocommerce-myparcel' ),  
  168. ),  
  169. ); 
  170.  
  171. add_settings_field( 
  172. 'email_tracktrace',  
  173. __( 'Track&trace in email', 'woocommerce-myparcel' ),  
  174. array( $this->callbacks, 'checkbox' ),  
  175. $option_group,  
  176. 'general',  
  177. array( 
  178. 'option_name' => $option_name,  
  179. 'id' => 'email_tracktrace',  
  180. 'description' => __( 'Add the track&trace code to emails to the customer.<br/><strong>Note!</strong> When you select this option, make sure you have not enabled the track & trace email in your MyParcel backend.', 'woocommerce-myparcel' ) 
  181. ); 
  182.  
  183. add_settings_field( 
  184. 'myaccount_tracktrace',  
  185. __( 'Track&trace in My Account', 'woocommerce-myparcel' ),  
  186. array( $this->callbacks, 'checkbox' ),  
  187. $option_group,  
  188. 'general',  
  189. array( 
  190. 'option_name' => $option_name,  
  191. 'id' => 'myaccount_tracktrace',  
  192. 'description' => __( 'Show track&trace trace code & link in My Account.', 'woocommerce-myparcel' ) 
  193. ); 
  194.  
  195. add_settings_field( 
  196. 'process_directly',  
  197. __( 'Process shipments directly', 'woocommerce-myparcel' ),  
  198. array( $this->callbacks, 'checkbox' ),  
  199. $option_group,  
  200. 'general',  
  201. array( 
  202. 'option_name' => $option_name,  
  203. 'id' => 'process_directly',  
  204. 'description' => __( 'When you enable this option, shipments will be directly processed when sent to myparcel.', 'woocommerce-myparcel' ) 
  205. ); 
  206.  
  207. add_settings_field( 
  208. 'order_status_automation',  
  209. __( 'Order status automation', 'woocommerce-myparcel' ),  
  210. array( $this->callbacks, 'checkbox' ),  
  211. $option_group,  
  212. 'general',  
  213. array( 
  214. 'option_name' => $option_name,  
  215. 'id' => 'order_status_automation',  
  216. 'description' => __( 'Automatically set order status to a predefined status after succesfull MyParcel 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-myparcel' ) 
  217. );  
  218.  
  219. add_settings_field( 
  220. 'automatic_order_status',  
  221. __( 'Automatic order status', 'woocommerce-myparcel' ),  
  222. array( $this->callbacks, 'order_status_select' ),  
  223. $option_group,  
  224. 'general',  
  225. array( 
  226. 'option_name' => $option_name,  
  227. 'id' => 'automatic_order_status',  
  228. 'class' => 'automatic_order_status',  
  229. );  
  230.  
  231. add_settings_field( 
  232. 'keep_shipments',  
  233. __( 'Keep old shipments', 'woocommerce-myparcel' ),  
  234. array( $this->callbacks, 'checkbox' ),  
  235. $option_group,  
  236. 'general',  
  237. array( 
  238. 'option_name' => $option_name,  
  239. 'id' => 'keep_shipments',  
  240. 'default' => 0,  
  241. '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-myparcel' ) 
  242. ); 
  243.  
  244. // Diagnostics section. 
  245. add_settings_section( 
  246. 'diagnostics',  
  247. __( 'Diagnostic tools', 'woocommerce-myparcel' ),  
  248. array( $this->callbacks, 'section' ),  
  249. $option_group 
  250. ); 
  251.  
  252. $upload_dir = wp_upload_dir(); 
  253. $upload_base_dir = trailingslashit( $upload_dir['basedir'] ); 
  254. $upload_base_url = trailingslashit( $upload_dir['baseurl'] ); 
  255. $log_file_url = $upload_base_url . 'myparcel_log.txt'; 
  256. $log_file_path = $upload_base_dir . 'myparcel_log.txt'; 
  257. $debugging_only = __( 'Only enable this option when debugging!', 'woocommerce-myparcel' ); 
  258. $download_link = sprintf('%s<br/><a href="%s" target="_blank">%s</a>', $debugging_only, $log_file_url, __( 'Download log file', 'woocommerce-myparcel' ) ); 
  259.  
  260. add_settings_field( 
  261. 'error_logging',  
  262. __( 'Log API communication', 'woocommerce-myparcel' ),  
  263. array( $this->callbacks, 'checkbox' ),  
  264. $option_group,  
  265. 'diagnostics',  
  266. array( 
  267. 'option_name' => $option_name,  
  268. 'id' => 'error_logging',  
  269. 'description' => file_exists($log_file_path) ? $download_link : $debugging_only,  
  270. ); 
  271.  
  272.  
  273. /** 
  274. * Register Export defaults settings 
  275. */ 
  276. public function export_defaults_settings() { 
  277. $option_group = 'woocommerce_myparcel_export_defaults_settings'; 
  278.  
  279. // Register settings. 
  280. $option_name = 'woocommerce_myparcel_export_defaults_settings'; 
  281. register_setting( $option_group, $option_name, array( $this->callbacks, 'validate' ) ); 
  282.  
  283. // Create option in wp_options. 
  284. if ( false === get_option( $option_name ) ) { 
  285. $this->default_settings( $option_name ); 
  286.  
  287. // API section. 
  288. add_settings_section( 
  289. 'defaults',  
  290. __( 'Default export settings', 'woocommerce-myparcel' ),  
  291. array( $this->callbacks, 'section' ),  
  292. $option_group 
  293. ); 
  294.  
  295.  
  296. if ( version_compare( WOOCOMMERCE_VERSION, '2.1', '>=' ) ) { 
  297. add_settings_field( 
  298. 'shipping_methods_package_types',  
  299. __( 'Package types', 'woocommerce-myparcel' ),  
  300. array( $this->callbacks, 'shipping_methods_package_types' ),  
  301. $option_group,  
  302. 'defaults',  
  303. array( 
  304. 'option_name' => $option_name,  
  305. 'id' => 'shipping_methods_package_types',  
  306. 'package_types' => WooCommerce_MyParcel()->export->get_package_types(),  
  307. 'description' => __( 'Select one or more shipping methods for each MyParcel package type', 'woocommerce-myparcel' ),  
  308. ); 
  309. } else { 
  310. add_settings_field( 
  311. 'package_type',  
  312. __( 'Shipment type', 'woocommerce-myparcel' ),  
  313. array( $this->callbacks, 'select' ),  
  314. $option_group,  
  315. 'defaults',  
  316. array( 
  317. 'option_name' => $option_name,  
  318. 'id' => 'package_type',  
  319. 'default' => '1',  
  320. 'options' => WooCommerce_MyParcel()->export->get_package_types(),  
  321. );  
  322.  
  323. add_settings_field( 
  324. 'connect_email',  
  325. __( 'Connect customer email', 'woocommerce-myparcel' ),  
  326. array( $this->callbacks, 'checkbox' ),  
  327. $option_group,  
  328. 'defaults',  
  329. array( 
  330. 'option_name' => $option_name,  
  331. 'id' => 'connect_email',  
  332. 'description' => sprintf(__( 'When you connect the customer email, MyParcel can send a Track&Trace email to this address. In your %sMyParcel backend%s you can enable or disable this email and format it in your own style.', 'woocommerce-myparcel' ), '<a href="https://backoffice.myparcel.nl/ttsettingstable" target="_blank">', '</a>') 
  333. ); 
  334.  
  335. add_settings_field( 
  336. 'connect_phone',  
  337. __( 'Connect customer phone', 'woocommerce-myparcel' ),  
  338. array( $this->callbacks, 'checkbox' ),  
  339. $option_group,  
  340. 'defaults',  
  341. array( 
  342. 'option_name' => $option_name,  
  343. 'id' => 'connect_phone',  
  344. '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-myparcel' ) 
  345. ); 
  346.  
  347. add_settings_field( 
  348. 'large_format',  
  349. __( 'Extra large size', 'woocommerce-myparcel' ).' (+ €2.29)',  
  350. array( $this->callbacks, 'checkbox' ),  
  351. $option_group,  
  352. 'defaults',  
  353. array( 
  354. 'option_name' => $option_name,  
  355. 'id' => 'large_format',  
  356. 'description' => __( 'Enable this option when your shipment is bigger than 100 x 70 x 50 cm, but smaller than 175 x 78 x 58 cm. An extra fee of € 2, 29 will be charged.<br/><strong>Note!</strong> If the parcel is bigger than 175 x 78 x 58 of or heavier than 30 kg, the pallet rate of € 70, 00 will be charged.', 'woocommerce-myparcel' ) 
  357. ); 
  358.  
  359. add_settings_field( 
  360. 'only_recipient',  
  361. __( 'Home address only', 'woocommerce-myparcel' ).' (+ €0.27)',  
  362. array( $this->callbacks, 'checkbox' ),  
  363. $option_group,  
  364. 'defaults',  
  365. array( 
  366. 'option_name' => $option_name,  
  367. 'id' => 'only_recipient',  
  368. 'description' => __( "If you don't want the parcel to be delivered at the neighbours, choose this option.", 'woocommerce-myparcel' ) 
  369. ); 
  370.  
  371. add_settings_field( 
  372. 'signature',  
  373. __( 'Signature on delivery', 'woocommerce-myparcel' ).' (+ €0.34)',  
  374. array( $this->callbacks, 'checkbox' ),  
  375. $option_group,  
  376. 'defaults',  
  377. array( 
  378. 'option_name' => $option_name,  
  379. 'id' => 'signature',  
  380. '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 signuture will be required.', 'woocommerce-myparcel' ) 
  381. ); 
  382.  
  383. // add_settings_field( 
  384. // 'home_address_signature',  
  385. // __( 'Home address only + signature on delivery', 'woocommerce-myparcel' ).' (+ €0.42)',  
  386. // array( $this->callbacks, 'checkbox' ),  
  387. // $option_group,  
  388. // 'defaults',  
  389. // array( 
  390. // 'option_name' => $option_name,  
  391. // 'id' => 'home_address_signature',  
  392. // 'description' => __( 'This is the secure option. The parcel will only be delivered at the recipient address, who has to sign for delivery. This way you can be certain the parcel will be handed to the recipient.', 'woocommerce-myparcel' ) 
  393. // ) 
  394. // )
  395.  
  396. add_settings_field( 
  397. 'return',  
  398. __( 'Return if no answer', 'woocommerce-myparcel' ),  
  399. array( $this->callbacks, 'checkbox' ),  
  400. $option_group,  
  401. 'defaults',  
  402. array( 
  403. 'option_name' => $option_name,  
  404. 'id' => 'return',  
  405. '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-myparcel' ) 
  406. ); 
  407.  
  408. add_settings_field( 
  409. 'insured',  
  410. __( 'Insured shipment (from + €0.50)', 'woocommerce-myparcel' ),  
  411. array( $this->callbacks, 'checkbox' ),  
  412. $option_group,  
  413. 'defaults',  
  414. array( 
  415. 'option_name' => $option_name,  
  416. 'id' => 'insured',  
  417. 'description' => __( 'By default, there is no insurance on the shipments. If you still want to insure the shipment, you can do that from €0.50. We insure the purchase value of the shipment, with a maximum insured value of € 5.000. Insured parcels always contain the options "Home address only" en "Signature for delivery"', 'woocommerce-myparcel' ),  
  418. 'class' => 'insured',  
  419. ); 
  420.  
  421. add_settings_field( 
  422. 'insured_amount',  
  423. __( 'Insured amount', 'woocommerce-myparcel' ),  
  424. array( $this->callbacks, 'select' ),  
  425. $option_group,  
  426. 'defaults',  
  427. array( 
  428. 'option_name' => $option_name,  
  429. 'id' => 'insured_amount',  
  430. 'default' => 'standard',  
  431. 'class' => 'insured_amount',  
  432. 'options' => array( 
  433. '49' => __( 'Insured up to € 50 (+ € 0.50)' , 'woocommerce-myparcel' ),  
  434. '249' => __( 'Insured up to € 250 (+ € 1.00)' , 'woocommerce-myparcel' ),  
  435. '499' => __( 'Insured up to € 500 (+ € 1.65)' , 'woocommerce-myparcel' ),  
  436. '' => __( '> € 500 insured (+ € 1.65 / € 500)' , 'woocommerce-myparcel' ),  
  437. ),  
  438. ); 
  439.  
  440. add_settings_field( 
  441. 'insured_amount_custom',  
  442. __( 'Insured amount (in euro)', 'woocommerce-myparcel' ),  
  443. array( $this->callbacks, 'text_input' ),  
  444. $option_group,  
  445. 'defaults',  
  446. array( 
  447. 'option_name' => $option_name,  
  448. 'id' => 'insured_amount_custom',  
  449. 'size' => '5',  
  450. 'class' => 'insured_amount',  
  451. ); 
  452.  
  453. add_settings_field( 
  454. 'label_description',  
  455. __( 'Label description', 'woocommerce-myparcel' ),  
  456. array( $this->callbacks, 'text_input' ),  
  457. $option_group,  
  458. 'defaults',  
  459. array( 
  460. 'option_name' => $option_name,  
  461. 'id' => 'label_description',  
  462. 'size' => '25',  
  463. '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 the MyParcel Backend. Use <strong>[ORDER_NR]</strong> to include the order number, <strong>[DELIVERY_DATE]</strong> to include the delivery date.", 'woocommerce-myparcel' ),  
  464. ); 
  465.  
  466. add_settings_field( 
  467. 'empty_parcel_weight',  
  468. __( 'Empty parcel weight (grams)', 'woocommerce-myparcel' ),  
  469. array( $this->callbacks, 'text_input' ),  
  470. $option_group,  
  471. 'defaults',  
  472. array( 
  473. 'option_name' => $option_name,  
  474. 'id' => 'empty_parcel_weight',  
  475. 'size' => '5',  
  476. 'description' => __( 'Default weight of your empty parcel, rounded to grams.', 'woocommerce-myparcel' ),  
  477. ); 
  478.  
  479.  
  480. /** 
  481. * Register Checkout settings 
  482. */ 
  483. public function checkout_settings() { 
  484. $option_group = 'woocommerce_myparcel_checkout_settings'; 
  485.  
  486. // Register settings. 
  487. $option_name = 'woocommerce_myparcel_checkout_settings'; 
  488. register_setting( $option_group, $option_name, array( $this->callbacks, 'validate' ) ); 
  489.  
  490. // Create option in wp_options. 
  491. if ( false === get_option( $option_name ) ) { 
  492. $this->default_settings( $option_name ); 
  493.  
  494. // Delivery options section. 
  495. add_settings_section( 
  496. 'delivery_options',  
  497. __( 'Delivery options', 'woocommerce-myparcel' ),  
  498. array( $this->callbacks, 'section' ),  
  499. $option_group 
  500. ); 
  501.  
  502.  
  503. add_settings_field( 
  504. 'myparcel_checkout',  
  505. __( 'Enable MyParcel delivery options', 'woocommerce-myparcel' ),  
  506. array( $this->callbacks, 'checkbox' ),  
  507. $option_group,  
  508. 'delivery_options',  
  509. array( 
  510. 'option_name' => $option_name,  
  511. 'id' => 'myparcel_checkout',  
  512. ); 
  513.  
  514. add_settings_field( 
  515. 'checkout_display',  
  516. __( 'Display for', 'woocommerce-myparcel' ),  
  517. array( $this->callbacks, 'select' ),  
  518. $option_group,  
  519. 'delivery_options',  
  520. array( 
  521. 'option_name' => $option_name,  
  522. 'id' => 'checkout_display',  
  523. 'options' => array( 
  524. 'selected_methods' => __( 'Shipping methods associated with Parcels' , 'woocommerce-myparcel' ),  
  525. 'all_methods' => __( 'All shipping methods' , 'woocommerce-myparcel' ),  
  526. ),  
  527. '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-myparcel' ),  
  528. ); 
  529.  
  530. add_settings_field( 
  531. 'only_recipient',  
  532. __( 'Home address only', 'woocommerce-myparcel' ),  
  533. array( $this->callbacks, 'delivery_option_enable' ),  
  534. $option_group,  
  535. 'delivery_options',  
  536. array( 
  537. 'option_name' => $option_name,  
  538. 'id' => 'only_recipient',  
  539. ); 
  540.  
  541. add_settings_field( 
  542. 'signed',  
  543. __( 'Signature on delivery', 'woocommerce-myparcel' ),  
  544. array( $this->callbacks, 'delivery_option_enable' ),  
  545. $option_group,  
  546. 'delivery_options',  
  547. array( 
  548. 'option_name' => $option_name,  
  549. 'id' => 'signed',  
  550. ); 
  551.  
  552. add_settings_field( 
  553. 'night',  
  554. __( 'Evening delivery', 'woocommerce-myparcel' ),  
  555. array( $this->callbacks, 'delivery_option_enable' ),  
  556. $option_group,  
  557. 'delivery_options',  
  558. array( 
  559. 'option_name' => $option_name,  
  560. 'id' => 'night',  
  561. ); 
  562.  
  563. add_settings_field( 
  564. 'morning',  
  565. __( 'Morning delivery', 'woocommerce-myparcel' ),  
  566. array( $this->callbacks, 'delivery_option_enable' ),  
  567. $option_group,  
  568. 'delivery_options',  
  569. array( 
  570. 'option_name' => $option_name,  
  571. 'id' => 'morning',  
  572. ); 
  573.  
  574. add_settings_field( 
  575. 'pickup',  
  576. __( 'PostNL pickup', 'woocommerce-myparcel' ),  
  577. array( $this->callbacks, 'delivery_option_enable' ),  
  578. $option_group,  
  579. 'delivery_options',  
  580. array( 
  581. 'option_name' => $option_name,  
  582. 'id' => 'pickup',  
  583. ); 
  584.  
  585. add_settings_field( 
  586. 'pickup_express',  
  587. __( 'Early PostNL pickup', 'woocommerce-myparcel' ),  
  588. array( $this->callbacks, 'delivery_option_enable' ),  
  589. $option_group,  
  590. 'delivery_options',  
  591. array( 
  592. 'option_name' => $option_name,  
  593. 'id' => 'pickup_express',  
  594. ); 
  595.  
  596. // Checkout options section. 
  597. add_settings_section( 
  598. 'processing_parameters',  
  599. __( 'Shipment processing parameters', 'woocommerce-myparcel' ),  
  600. array( $this->callbacks, 'section' ),  
  601. $option_group 
  602. ); 
  603.  
  604. $days_of_the_week = array( 
  605. '0' => __( 'Sunday', 'woocommerce-myparcel' ),  
  606. '1' => __( 'Monday', 'woocommerce-myparcel' ),  
  607. '2' => __( 'Tuesday', 'woocommerce-myparcel' ),  
  608. '3' => __( 'Wednesday', 'woocommerce-myparcel' ),  
  609. '4' => __( 'Thursday', 'woocommerce-myparcel' ),  
  610. '5' => __( 'Friday', 'woocommerce-myparcel' ),  
  611. '6' => __( 'Saturday', 'woocommerce-myparcel' ),  
  612. ); 
  613.  
  614. add_settings_field( 
  615. 'dropoff_days',  
  616. __( 'Dropoff days', 'woocommerce-myparcel' ),  
  617. array( $this->callbacks, 'enhanced_select' ),  
  618. $option_group,  
  619. 'processing_parameters',  
  620. array( 
  621. 'option_name' => $option_name,  
  622. 'id' => 'dropoff_days',  
  623. 'options' => $days_of_the_week,  
  624. 'description' => __( 'Days of the week on which you hand over parcels to PostNL', 'woocommerce-myparcel' ),  
  625. ); 
  626.  
  627. add_settings_field( 
  628. 'cutoff_time',  
  629. __( 'Cut-off time', 'woocommerce-myparcel' ),  
  630. array( $this->callbacks, 'text_input' ),  
  631. $option_group,  
  632. 'processing_parameters',  
  633. array( 
  634. 'option_name' => $option_name,  
  635. 'id' => 'cutoff_time',  
  636. 'type' => 'text',  
  637. 'size' => '5',  
  638. 'description' => __( 'Time at which you stop processing orders for the day (format: hh:mm)', 'woocommerce-myparcel' ),  
  639. ); 
  640.  
  641. add_settings_field( 
  642. 'dropoff_delay',  
  643. __( 'Dropoff delay', 'woocommerce-myparcel' ),  
  644. array( $this->callbacks, 'text_input' ),  
  645. $option_group,  
  646. 'processing_parameters',  
  647. array( 
  648. 'option_name' => $option_name,  
  649. 'id' => 'dropoff_delay',  
  650. 'type' => 'number',  
  651. 'size' => '2',  
  652. 'description' => __( 'Number of days you take to process an order', 'woocommerce-myparcel' ),  
  653. ); 
  654.  
  655. add_settings_field( 
  656. 'deliverydays_window',  
  657. __( 'Delivery days window', 'woocommerce-myparcel' ),  
  658. array( $this->callbacks, 'text_input' ),  
  659. $option_group,  
  660. 'processing_parameters',  
  661. array( 
  662. 'option_name' => $option_name,  
  663. 'id' => 'deliverydays_window',  
  664. 'type' => 'number',  
  665. 'size' => '2',  
  666. 'description' => __( 'Number of days you allow the customer to postpone a shipment', 'woocommerce-myparcel' ),  
  667. ); 
  668.  
  669. // Customizations section 
  670. add_settings_section( 
  671. 'customizations',  
  672. __( 'Customizations', 'woocommerce-myparcel' ),  
  673. array( $this->callbacks, 'section' ),  
  674. $option_group 
  675. ); 
  676.  
  677. add_settings_field( 
  678. 'base_color',  
  679. __( 'Base color', 'woocommerce-myparcel' ),  
  680. array( $this->callbacks, 'color_picker' ),  
  681. $option_group,  
  682. 'customizations',  
  683. array( 
  684. 'option_name' => $option_name,  
  685. 'id' => 'base_color',  
  686. 'size' => '10',  
  687. 'description' => __( 'Color of the header & tabs (cyan by default)', 'woocommerce-myparcel' ),  
  688. ); 
  689.  
  690.  
  691. add_settings_field( 
  692. 'highlight_color',  
  693. __( 'Highlight color', 'woocommerce-myparcel' ),  
  694. array( $this->callbacks, 'color_picker' ),  
  695. $option_group,  
  696. 'customizations',  
  697. array( 
  698. 'option_name' => $option_name,  
  699. 'id' => 'highlight_color',  
  700. 'size' => '10',  
  701. 'description' => __( 'Color of the selections/highlights (orange by default)', 'woocommerce-myparcel' ),  
  702. ); 
  703.  
  704. add_settings_field( 
  705. 'custom_css',  
  706. __( 'Custom styles', 'woocommerce-myparcel' ),  
  707. array( $this->callbacks, 'textarea' ),  
  708. $option_group,  
  709. 'customizations',  
  710. array( 
  711. 'option_name' => $option_name,  
  712. 'id' => 'custom_css',  
  713. 'width' => '80',  
  714. 'height' => '8',  
  715. ); 
  716.  
  717. add_settings_field( 
  718. 'autoload_google_fonts',  
  719. __( 'Automatically load Google fonts', 'woocommerce-myparcel' ),  
  720. array( $this->callbacks, 'checkbox' ),  
  721. $option_group,  
  722. 'customizations',  
  723. array( 
  724. 'option_name' => $option_name,  
  725. 'id' => 'autoload_google_fonts',  
  726. ); 
  727.  
  728.  
  729. /** 
  730. * Set default settings. 
  731. *  
  732. * @return void. 
  733. */ 
  734. public function default_settings( $option ) { 
  735. // $default = array( 
  736. // 'process' => '1',  
  737. // 'keep_consignments' => '0',  
  738. // 'download_display' => 'download',  
  739. // 'email' => '1',  
  740. // 'telefoon' => '1',  
  741. // 'extragroot' => '0',  
  742. // 'huisadres' => '0',  
  743. // 'handtekening' => '0',  
  744. // 'huishand' => '0',  
  745. // 'retourbgg' => '0',  
  746. // 'verzekerd' => '0',  
  747. // 'verzekerdbedrag' => '0',  
  748. // 'kenmerk' => '',  
  749. // 'verpakkingsgewicht'=> '0',  
  750. // )
  751.  
  752. // add_option( 'wcmyparcel_settings', $default ); 
  753.  
  754. switch ( $option ) { 
  755. case 'woocommerce_myparcel_general_settings': 
  756. $default = array( 
  757.  
  758. ); 
  759. break; 
  760. case 'woocommerce_myparcel_checkout_settings': 
  761. $default = array ( 
  762. 'pickup_enabled' => '1',  
  763. 'dropoff_days' => array ( 1, 2, 3, 4, 5 ),  
  764. 'dropoff_delay' => '0',  
  765. 'deliverydays_window' => '1',  
  766. ); 
  767. break; 
  768. case 'woocommerce_myparcel_export_defaults_settings': 
  769. default: 
  770. $default = array(); 
  771. break; 
  772.  
  773. if ( false === get_option( $option ) ) { 
  774. add_option( $option, $default ); 
  775. } else { 
  776. update_option( $option, $default ); 
  777.  
  778. endif; // class_exists 
  779.  
  780. return new WooCommerce_MyParcel_Settings(); 
.