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-frontend-settings.php

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

142 lines 3.3 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_Frontend_Settings')) :
6
7 /**
8 * Frontend settings
9 */
10 class WooCommerce_PostNL_Frontend_Settings {
11
12 const DAYS_SATURDAY = 6;
13 const CARRIER_CODE = 1;
14 const CARRIER_NAME = "PostNL";
15 const BASE_URL = "https://api.myparcel.nl/";
16 private static $settings;
17
18 function __construct() {
19 self::$settings = WooCommerce_PostNL()->checkout_settings;
20 }
21
22 /**
23 * Check if given option is enabled
24 * @return bool
25 */
26 public static function is_enabled($option) {
27 $option = $option . "_enabled";
28
29 if (isset(self::$settings[$option])) {
30 return self::$settings[$option] ? 1 : 0;
31 }
32
33 return 0;
34 }
35
36 /**
37 * Get given option title
38 * @return string
39 */
40 public static function get_title($option) {
41 $option = $option . "_title";
42
43 if (isset(self::$settings[$option])) {
44 return self::$settings[$option];
45 }
46
47 return WooCommerce_PostNL_Settings::get_checkout_setting_title($option);
48 }
49
50 /**
51 * Get price of given option
52 * @return float
53 */
54 public static function get_price($option) {
55 $option = $option . "_fee";
56
57 if (isset(WooCommerce_PostNL_Frontend_Settings::$settings[$option])) {
58 $price = self::$settings[$option];
59 $total_price = self::get_total_price_with_tax($price);
60
61 return $total_price;
62 }
63
64 return 0;
65 }
66
67 /**
68 * @return mixed
69 * cut-off time for monday delivery
70 */
71 public function get_saturday_cutoff_time() {
72 if (isset(self::$settings['saturday_cutoff_time'])) {
73 return self::$settings['saturday_cutoff_time'];
74 }
75 }
76
77 /**
78 * @return mixed
79 */
80 public function get_cutoff_time() {
81 if (date_i18n('w') == self::DAYS_SATURDAY
82 && isset(self::$settings['saturday_cutoff_time'])) {
83 return self::$settings['saturday_cutoff_time'];
84 }
85
86 return self::$settings['cutoff_time'];
87 }
88
89 /**
90 * @return mixed
91 */
92 public function get_dropoff_delay() {
93 if (isset(self::$settings['dropoff_delay'])) {
94 return self::$settings['dropoff_delay'];
95 }
96
97 return 0;
98 }
99
100 /**
101 * @return mixed
102 */
103 public function get_deliverydays_window() {
104 if (isset(self::$settings['deliverydays_window'])) {
105 return (int) self::$settings['deliverydays_window'];
106 }
107
108 return 0;
109 }
110
111 /**
112 * @return string
113 */
114 public function get_dropoff_days() {
115 return implode(";", self::$settings['dropoff_days']);
116 }
117
118 /**
119 * @return string
120 */
121 public function get_country_code() {
122 return WC()->customer->get_shipping_country();
123 }
124
125 /**
126 * @param $price
127 *
128 * @return string
129 */
130 public static function get_total_price_with_tax($price) {
131 $price = (float) $price;
132 $base_tax_rates = WC_Tax::get_base_tax_rates('');
133 $base_tax_key = key($base_tax_rates);
134 $taxRate = isset($base_tax_key) ? (float) $base_tax_rates[$base_tax_key]['rate'] : 0;
135 $tax = $price * $taxRate / 100;
136 $total_price = (float) number_format($price + $tax, 2);
137
138 return $total_price;
139 }
140 }
141
142 endif; // class_exists