| 1 |
<?php |
| 2 |
|
| 3 |
use MyParcelNL\Sdk\src\Model\Consignment\PostNLConsignment; |
| 4 |
use WPO\WC\PostNL\Entity\SettingsFieldArguments; |
| 5 |
|
| 6 |
if (! defined('ABSPATH')) { |
| 7 |
exit; |
| 8 |
} |
| 9 |
|
| 10 |
if (class_exists('WCPN_Settings_Data')) { |
| 11 |
return new WCPN_Settings_Data(); |
| 12 |
} |
| 13 |
|
| 14 |
/** |
| 15 |
* This class contains all data for the admin settings screens created by the plugin. |
| 16 |
*/ |
| 17 |
class WCPN_Settings_Data |
| 18 |
{ |
| 19 |
public const ENABLED = "1"; |
| 20 |
public const DISABLED = "0"; |
| 21 |
|
| 22 |
public const DISPLAY_FOR_SELECTED_METHODS = "selected_methods"; |
| 23 |
public const DISPLAY_FOR_ALL_METHODS = "all_methods"; |
| 24 |
|
| 25 |
public const DISPLAY_TOTAL_PRICE = "total_price"; |
| 26 |
public const DISPLAY_SURCHARGE_PRICE = "surcharge"; |
| 27 |
|
| 28 |
public const PICKUP_LOCATIONS_VIEW_MAP = "map"; |
| 29 |
public const PICKUP_LOCATIONS_VIEW_LIST = "list"; |
| 30 |
|
| 31 |
public const CHANGE_STATUS_AFTER_PRINTING = "after_printing"; |
| 32 |
public const CHANGE_STATUS_AFTER_EXPORT = "after_export"; |
| 33 |
|
| 34 |
public const NOT_ACTIVE = "notActive"; |
| 35 |
public const NO_OPTIONS = "noOptions"; |
| 36 |
public const EQUAL_TO_SHIPMENT = "equalToShipment"; |
| 37 |
|
| 38 |
/** |
| 39 |
* @var WCPN_Settings_Callbacks |
| 40 |
*/ |
| 41 |
private $callbacks; |
| 42 |
|
| 43 |
public function __construct() |
| 44 |
{ |
| 45 |
$this->callbacks = require 'class-wcpn-settings-callbacks.php'; |
| 46 |
|
| 47 |
// Create the PostNL settings with the admin_init hook. |
| 48 |
add_action("admin_init", [$this, "create_all_settings"]); |
| 49 |
} |
| 50 |
|
| 51 |
/** |
| 52 |
* Create all settings sections. |
| 53 |
* |
| 54 |
* @throws \Exception |
| 55 |
*/ |
| 56 |
public function create_all_settings(): void |
| 57 |
{ |
| 58 |
$this->generate_settings( |
| 59 |
$this->get_sections_general(), |
| 60 |
WCPOST_Settings::SETTINGS_GENERAL |
| 61 |
); |
| 62 |
|
| 63 |
$this->generate_settings( |
| 64 |
$this->get_sections_export_defaults(), |
| 65 |
WCPOST_Settings::SETTINGS_EXPORT_DEFAULTS |
| 66 |
); |
| 67 |
|
| 68 |
$this->generate_settings( |
| 69 |
$this->get_sections_checkout(), |
| 70 |
WCPOST_Settings::SETTINGS_CHECKOUT |
| 71 |
); |
| 72 |
|
| 73 |
$this->generate_settings( |
| 74 |
$this->get_sections_carrier_postnl(), |
| 75 |
WCPOST_Settings::SETTINGS_POSTNL, |
| 76 |
true |
| 77 |
); |
| 78 |
} |
| 79 |
|
| 80 |
/** |
| 81 |
* @return array |
| 82 |
*/ |
| 83 |
public static function getTabs(): array |
| 84 |
{ |
| 85 |
$array = [ |
| 86 |
WCPOST_Settings::SETTINGS_GENERAL => __("General", "woocommerce-postnl"), |
| 87 |
WCPOST_Settings::SETTINGS_EXPORT_DEFAULTS => __("Default export settings", "woocommerce-postnl"), |
| 88 |
WCPOST_Settings::SETTINGS_CHECKOUT => __("Checkout settings", "woocommerce-postnl"), |
| 89 |
]; |
| 90 |
|
| 91 |
$array[WCPOST_Settings::SETTINGS_POSTNL] = __("PostNL", "woocommerce-postnl"); |
| 92 |
|
| 93 |
return $array; |
| 94 |
} |
| 95 |
|
| 96 |
/** |
| 97 |
* Generate settings sections and fields by the given $settingsArray. |
| 98 |
* |
| 99 |
* @param array $settingsArray - Array of settings to loop through. |
| 100 |
* @param string $optionName - Name to use in the identifier. |
| 101 |
* @param bool $prefix - Add the key of the top level settings as prefix before every setting or not. |
| 102 |
* |
| 103 |
* @throws \Exception |
| 104 |
*/ |
| 105 |
private function generate_settings(array $settingsArray, string $optionName, bool $prefix = false): void |
| 106 |
{ |
| 107 |
$optionIdentifier = WCPOST_Settings::getOptionId($optionName); |
| 108 |
$defaults = []; |
| 109 |
|
| 110 |
// Register settings. |
| 111 |
register_setting($optionIdentifier, $optionIdentifier, [$this->callbacks, 'validate']); |
| 112 |
|
| 113 |
foreach ($settingsArray as $name => $array) { |
| 114 |
foreach ($array as $section) { |
| 115 |
$sectionName = "{$name}_{$section["name"]}"; |
| 116 |
|
| 117 |
add_settings_section( |
| 118 |
$sectionName, |
| 119 |
$section["label"], |
| 120 |
/** |
| 121 |
* Allows a description to be shown with a section title. |
| 122 |
*/ |
| 123 |
static function() use ($section) { |
| 124 |
WCPN_Settings_Callbacks::renderSection($section); |
| 125 |
}, |
| 126 |
$optionIdentifier |
| 127 |
); |
| 128 |
|
| 129 |
foreach ($section["settings"] as $setting) { |
| 130 |
$namePrefix = $prefix ? "{$name}_" : ''; |
| 131 |
$setting["id"] = $prefix ? "{$name}_{$setting["name"]}" : $setting["name"]; |
| 132 |
$setting["option_id"] = $optionIdentifier; |
| 133 |
|
| 134 |
$class = new SettingsFieldArguments($setting, "{$optionIdentifier}[{$namePrefix}", ']'); |
| 135 |
|
| 136 |
// Add the setting's default value to the defaults array. |
| 137 |
$defaults[$setting["id"]] = $class->getDefault(); |
| 138 |
|
| 139 |
if (isset(get_option($optionIdentifier)[$class->getId()])) { |
| 140 |
$class->setValue(get_option($optionIdentifier)[$class->getId()]); |
| 141 |
} |
| 142 |
|
| 143 |
// Default callback |
| 144 |
$callback = static function() use ($class) { |
| 145 |
WCPN_Settings_Callbacks::renderField($class); |
| 146 |
}; |
| 147 |
|
| 148 |
// Pass the class to custom callbacks as well. |
| 149 |
if (isset($setting['callback'])) { |
| 150 |
$callback = static function () use ($setting, $class) { |
| 151 |
call_user_func($setting["callback"], $class); |
| 152 |
}; |
| 153 |
} |
| 154 |
|
| 155 |
add_settings_field( |
| 156 |
$setting["id"], |
| 157 |
$setting["label"], |
| 158 |
$callback, |
| 159 |
$optionIdentifier, |
| 160 |
$sectionName, |
| 161 |
// If a custom callback is used, send the $setting as arguments. Otherwise use the created |
| 162 |
// arguments from the class. |
| 163 |
isset($setting["callback"]) ? $setting : $class->getArguments() |
| 164 |
); |
| 165 |
} |
| 166 |
} |
| 167 |
} |
| 168 |
|
| 169 |
// Create option in wp_options with default settings if the option doesn't exist yet. |
| 170 |
if (false === get_option($optionIdentifier)) { |
| 171 |
add_option($optionIdentifier, $defaults); |
| 172 |
} |
| 173 |
|
| 174 |
// Merge any missing values into the settings |
| 175 |
update_option( |
| 176 |
$optionIdentifier, |
| 177 |
array_replace_recursive( |
| 178 |
$defaults, |
| 179 |
get_option($optionIdentifier) |
| 180 |
) |
| 181 |
); |
| 182 |
} |
| 183 |
|
| 184 |
/** |
| 185 |
* @return array |
| 186 |
*/ |
| 187 |
private function get_sections_general() |
| 188 |
{ |
| 189 |
return [ |
| 190 |
WCPOST_Settings::SETTINGS_GENERAL => [ |
| 191 |
[ |
| 192 |
"name" => "api", |
| 193 |
"label" => __("API settings", "woocommerce-postnl"), |
| 194 |
"settings" => $this->get_section_general_api(), |
| 195 |
], |
| 196 |
[ |
| 197 |
"name" => "general", |
| 198 |
"label" => __("General settings", "woocommerce-postnl"), |
| 199 |
"settings" => $this->get_section_general_general(), |
| 200 |
], |
| 201 |
[ |
| 202 |
"name" => "diagnostics", |
| 203 |
"label" => __("Diagnostic tools", "woocommerce-postnl"), |
| 204 |
"settings" => $this->get_section_general_diagnostics(), |
| 205 |
], |
| 206 |
], |
| 207 |
]; |
| 208 |
} |
| 209 |
|
| 210 |
/** |
| 211 |
* @return array |
| 212 |
*/ |
| 213 |
private function get_sections_export_defaults() |
| 214 |
{ |
| 215 |
return [ |
| 216 |
WCPOST_Settings::SETTINGS_EXPORT_DEFAULTS => [ |
| 217 |
[ |
| 218 |
"name" => "main", |
| 219 |
"label" => __("Default export settings", "woocommerce-postnl"), |
| 220 |
"settings" => $this->get_section_export_defaults_main(), |
| 221 |
], |
| 222 |
], |
| 223 |
]; |
| 224 |
} |
| 225 |
|
| 226 |
private function get_sections_checkout() |
| 227 |
{ |
| 228 |
return [ |
| 229 |
WCPOST_Settings::SETTINGS_CHECKOUT => [ |
| 230 |
[ |
| 231 |
"name" => "main", |
| 232 |
"label" => __("Checkout settings", "woocommerce-postnl"), |
| 233 |
"settings" => $this->get_section_checkout_main(), |
| 234 |
], |
| 235 |
[ |
| 236 |
"name" => "strings", |
| 237 |
"label" => __("Titles", "woocommerce-postnl"), |
| 238 |
"condition" => WCPOST_Settings::SETTING_DELIVERY_OPTIONS_ENABLED, |
| 239 |
"settings" => $this->get_section_checkout_strings(), |
| 240 |
], |
| 241 |
], |
| 242 |
]; |
| 243 |
} |
| 244 |
|
| 245 |
/** |
| 246 |
* Get the array of PostNL sections and their settings to be added to WordPress. |
| 247 |
* |
| 248 |
* @return array |
| 249 |
*/ |
| 250 |
private function get_sections_carrier_postnl() |
| 251 |
{ |
| 252 |
return [ |
| 253 |
PostNLConsignment::CARRIER_NAME => [ |
| 254 |
[ |
| 255 |
"name" => "export_defaults", |
| 256 |
"label" => __("PostNL export settings", "woocommerce-postnl"), |
| 257 |
"description" => __( |
| 258 |
"These settings will be applied to PostNL shipments you create in the backend.", |
| 259 |
"woocommerce-postnl" |
| 260 |
), |
| 261 |
"settings" => $this->get_section_carrier_postnl_export_defaults(), |
| 262 |
], |
| 263 |
[ |
| 264 |
"name" => "delivery_options", |
| 265 |
"label" => __("PostNL delivery options", "woocommerce-postnl"), |
| 266 |
"settings" => $this->get_section_carrier_postnl_delivery_options(), |
| 267 |
], |
| 268 |
[ |
| 269 |
"name" => "pickup_options", |
| 270 |
"label" => __("PostNL pickup options", "woocommerce-postnl"), |
| 271 |
"settings" => $this->get_section_carrier_postnl_pickup_options(), |
| 272 |
], |
| 273 |
], |
| 274 |
]; |
| 275 |
} |
| 276 |
|
| 277 |
/** |
| 278 |
* @return array |
| 279 |
*/ |
| 280 |
private function get_section_general_api(): array |
| 281 |
{ |
| 282 |
return [ |
| 283 |
[ |
| 284 |
"name" => WCPOST_Settings::SETTING_API_KEY, |
| 285 |
"label" => __("Key", "woocommerce-postnl"), |
| 286 |
"help_text" => __("api key", "woocommerce-postnl"), |
| 287 |
], |
| 288 |
]; |
| 289 |
} |
| 290 |
|
| 291 |
/** |
| 292 |
* @return array |
| 293 |
*/ |
| 294 |
private function get_section_general_general(): array |
| 295 |
{ |
| 296 |
return [ |
| 297 |
[ |
| 298 |
"name" => WCPOST_Settings::SETTING_DOWNLOAD_DISPLAY, |
| 299 |
"label" => __("Label display", "woocommerce-postnl"), |
| 300 |
"type" => "select", |
| 301 |
"options" => [ |
| 302 |
"download" => __("Download PDF", "woocommerce-postnl"), |
| 303 |
"display" => __("Open the PDF in a new tab", "woocommerce-postnl"), |
| 304 |
], |
| 305 |
], |
| 306 |
[ |
| 307 |
"name" => WCPOST_Settings::SETTING_LABEL_FORMAT, |
| 308 |
"label" => __("Label format", "woocommerce-postnl"), |
| 309 |
"type" => "select", |
| 310 |
"options" => [ |
| 311 |
"A4" => __("Standard printer (A4)", "woocommerce-postnl"), |
| 312 |
"A6" => __("Label Printer (A6)", "woocommerce-postnl"), |
| 313 |
], |
| 314 |
], |
| 315 |
[ |
| 316 |
"name" => WCPOST_Settings::SETTING_ASK_FOR_PRINT_POSITION, |
| 317 |
"label" => __("Ask for print start position", "woocommerce-postnl"), |
| 318 |
"condition" => [ |
| 319 |
"parent_name" => WCPOST_Settings::SETTING_LABEL_FORMAT, |
| 320 |
"type" => "disable", |
| 321 |
"parent_value" => "A4", |
| 322 |
"set_value" => self::DISABLED, |
| 323 |
], |
| 324 |
"type" => "toggle", |
| 325 |
"help_text" => __( |
| 326 |
"This option enables you to continue printing where you left off last time", |
| 327 |
"woocommerce-postnl" |
| 328 |
), |
| 329 |
], |
| 330 |
[ |
| 331 |
"name" => WCPOST_Settings::SETTING_TRACK_TRACE_EMAIL, |
| 332 |
"label" => __("Track & Trace in email", "woocommerce-postnl"), |
| 333 |
"type" => "toggle", |
| 334 |
"help_text" => __( |
| 335 |
"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 PostNL backend.", |
| 336 |
"woocommerce-postnl" |
| 337 |
), |
| 338 |
], |
| 339 |
[ |
| 340 |
"name" => WCPOST_Settings::SETTING_TRACK_TRACE_MY_ACCOUNT, |
| 341 |
"label" => __("Track & Trace in My Account", "woocommerce-postnl"), |
| 342 |
"type" => "toggle", |
| 343 |
"help_text" => __("Show Track & Trace trace code and link in My Account.", "woocommerce-postnl"), |
| 344 |
], |
| 345 |
[ |
| 346 |
"name" => WCPOST_Settings::SETTING_PROCESS_DIRECTLY, |
| 347 |
"label" => __("Process shipments directly", "woocommerce-postnl"), |
| 348 |
"type" => "toggle", |
| 349 |
"help_text" => __( |
| 350 |
"When you enable this option, shipments will be directly processed when sent to PostNL.", |
| 351 |
"woocommerce-postnl" |
| 352 |
), |
| 353 |
], |
| 354 |
[ |
| 355 |
"name" => WCPOST_Settings::SETTING_ORDER_STATUS_AUTOMATION, |
| 356 |
"label" => __("Order status automation", "woocommerce-postnl"), |
| 357 |
"type" => "toggle", |
| 358 |
"help_text" => __( |
| 359 |
"Automatically set order status to a predefined status after successful PostNL 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.", |
| 360 |
"woocommerce-postnl" |
| 361 |
), |
| 362 |
], |
| 363 |
[ |
| 364 |
"name" => WCPOST_Settings::SETTING_CHANGE_ORDER_STATUS_AFTER, |
| 365 |
"condition" => WCPOST_Settings::SETTING_ORDER_STATUS_AUTOMATION, |
| 366 |
"class" => ["wcpn__child"], |
| 367 |
"label" => __("setting_change_order_status_after", "woocommerce-postnl"), |
| 368 |
"type" => "select", |
| 369 |
"default" => self::CHANGE_STATUS_AFTER_PRINTING, |
| 370 |
"options" => [ |
| 371 |
self::CHANGE_STATUS_AFTER_PRINTING => __("setting_change_status_after_printing", "woocommerce-postnl"), |
| 372 |
self::CHANGE_STATUS_AFTER_EXPORT => __("setting_change_status_after_export", "woocommerce-postnl"), |
| 373 |
], |
| 374 |
"help_text" => __( |
| 375 |
"setting_change_status_after_help_text", |
| 376 |
"woocommerce-postnl" |
| 377 |
), |
| 378 |
], |
| 379 |
[ |
| 380 |
"name" => WCPOST_Settings::SETTING_AUTOMATIC_ORDER_STATUS, |
| 381 |
"condition" => WCPOST_Settings::SETTING_ORDER_STATUS_AUTOMATION, |
| 382 |
"class" => ["wcpn__child"], |
| 383 |
"label" => __("setting_automatic_order_status", "woocommerce-postnl"), |
| 384 |
"type" => "select", |
| 385 |
"options" => WCPN_Settings_Callbacks::get_order_status_options(), |
| 386 |
], |
| 387 |
[ |
| 388 |
"name" => WCPOST_Settings::SETTING_BARCODE_IN_NOTE, |
| 389 |
"label" => __("Place barcode inside note", "woocommerce-postnl"), |
| 390 |
"type" => "toggle", |
| 391 |
"help_text" => __("Place the barcode inside a note of the order", "woocommerce-postnl"), |
| 392 |
], |
| 393 |
[ |
| 394 |
"name" => WCPOST_Settings::SETTING_BARCODE_IN_NOTE_TITLE, |
| 395 |
"condition" => WCPOST_Settings::SETTING_BARCODE_IN_NOTE, |
| 396 |
"class" => ["wcpn__child"], |
| 397 |
"label" => __("Title before the barcode", "woocommerce-postnl"), |
| 398 |
"default" => __("Track & trace code:", "woocommerce-postnl"), |
| 399 |
"help_text" => __( |
| 400 |
"You can change the text before the barcode inside an note", |
| 401 |
"woocommerce-postnl" |
| 402 |
), |
| 403 |
], |
| 404 |
]; |
| 405 |
} |
| 406 |
|
| 407 |
/** |
| 408 |
* @return array |
| 409 |
*/ |
| 410 |
private function get_section_general_diagnostics(): array |
| 411 |
{ |
| 412 |
return [ |
| 413 |
[ |
| 414 |
"name" => WCPOST_Settings::SETTING_ERROR_LOGGING, |
| 415 |
"label" => __("Log API communication", "woocommerce-postnl"), |
| 416 |
"type" => "toggle", |
| 417 |
"description" => '<a href="' . esc_url_raw( |
| 418 |
admin_url("admin.php?page=wc-status&tab=logs") |
| 419 |
) . '" target="_blank">' . __("View logs", "woocommerce-postnl") . "</a> (wc-postnl)", |
| 420 |
], |
| 421 |
]; |
| 422 |
} |
| 423 |
|
| 424 |
/** |
| 425 |
* Export defaults specifically for postnl. |
| 426 |
* |
| 427 |
* @return array |
| 428 |
*/ |
| 429 |
private function get_section_carrier_postnl_export_defaults(): array |
| 430 |
{ |
| 431 |
return [ |
| 432 |
[ |
| 433 |
"name" => WCPOST_Settings::SETTING_CARRIER_DEFAULT_EXPORT_ONLY_RECIPIENT, |
| 434 |
"label" => __("shipment_options_only_recipient", "woocommerce-postnl"), |
| 435 |
"help_text" => __("shipment_options_only_recipient_help_text", "woocommerce-postnl"), |
| 436 |
"type" => "toggle", |
| 437 |
], |
| 438 |
[ |
| 439 |
"name" => WCPOST_Settings::SETTING_CARRIER_DEFAULT_EXPORT_SIGNATURE, |
| 440 |
"label" => __("shipment_options_signature", "woocommerce-postnl"), |
| 441 |
"help_text" => __("shipment_options_signature_help_text", "woocommerce-postnl"), |
| 442 |
"type" => "toggle", |
| 443 |
], |
| 444 |
// [ |
| 445 |
// "name" => WCPOST_Settings::SETTING_CARRIER_DEFAULT_EXPORT_LARGE_FORMAT, |
| 446 |
// "label" => __("shipment_options_large_format", "woocommerce-postnl"), |
| 447 |
// "help_text" => __("shipment_options_large_format_help_text", "woocommerce-postnl"), |
| 448 |
// "type" => "toggle", |
| 449 |
// ], |
| 450 |
[ |
| 451 |
"name" => WCPOST_Settings::SETTING_CARRIER_DEFAULT_EXPORT_AGE_CHECK, |
| 452 |
"label" => __("shipment_options_age_check", "woocommerce-postnl"), |
| 453 |
"type" => "toggle", |
| 454 |
"help_text" => __("shipment_options_age_check_help_text", "woocommerce-postnl"), |
| 455 |
], |
| 456 |
[ |
| 457 |
"name" => WCPOST_Settings::SETTING_CARRIER_DEFAULT_EXPORT_RETURN, |
| 458 |
"label" => __("shipment_options_return", "woocommerce-postnl"), |
| 459 |
"help_text" => __("shipment_options_return_help_text", "woocommerce-postnl"), |
| 460 |
"type" => "toggle", |
| 461 |
], |
| 462 |
[ |
| 463 |
"name" => WCPOST_Settings::SETTING_CARRIER_DEFAULT_EXPORT_INSURED, |
| 464 |
"label" => __("shipment_options_insured", "woocommerce-postnl"), |
| 465 |
"help_text" => __("shipment_options_insured_help_text", "woocommerce-postnl"), |
| 466 |
"type" => "toggle", |
| 467 |
], |
| 468 |
[ |
| 469 |
"name" => WCPOST_Settings::SETTING_CARRIER_DEFAULT_EXPORT_INSURED_FROM_PRICE, |
| 470 |
"condition" => WCPOST_Settings::SETTING_CARRIER_DEFAULT_EXPORT_INSURED, |
| 471 |
"label" => __("shipment_options_insured_from_price", "woocommerce-postnl"), |
| 472 |
"help_text" => __("shipment_options_insured_from_price_help_text", "woocommerce-postnl"), |
| 473 |
"type" => "number", |
| 474 |
], |
| 475 |
[ |
| 476 |
"name" => WCPOST_Settings::SETTING_CARRIER_DEFAULT_EXPORT_INSURED_AMOUNT, |
| 477 |
"condition" => WCPOST_Settings::SETTING_CARRIER_DEFAULT_EXPORT_INSURED, |
| 478 |
"label" => __("shipment_options_insured_amount", "woocommerce-postnl"), |
| 479 |
"help_text" => __("shipment_options_insured_amount_help_text", "woocommerce-postnl"), |
| 480 |
"type" => "select", |
| 481 |
"options" => WCPN_Data::getInsuranceAmounts(), |
| 482 |
], |
| 483 |
[ |
| 484 |
'name' => WCPOST_Settings::SETTING_CARRIER_DEFAULT_EXPORT_INSURED_FOR_BE, |
| 485 |
'condition' => WCPOST_Settings::SETTING_CARRIER_DEFAULT_EXPORT_INSURED, |
| 486 |
'label' => __('shipment_options_insured_for_be', 'woocommerce-postnl'), |
| 487 |
'default' => self::ENABLED, |
| 488 |
'help_text' => __('shipment_options_insured_for_be_help_text', 'woocommerce-postnl'), |
| 489 |
'type' => 'toggle', |
| 490 |
] |
| 491 |
]; |
| 492 |
} |
| 493 |
|
| 494 |
/** |
| 495 |
* These are the unprefixed settings for postnl. |
| 496 |
* After the settings are generated every name will be prefixed with "postnl_" |
| 497 |
* Example: delivery_enabled => postnl_delivery_enabled |
| 498 |
* |
| 499 |
* @return array |
| 500 |
*/ |
| 501 |
private function get_section_carrier_postnl_delivery_options(): array |
| 502 |
{ |
| 503 |
return [ |
| 504 |
[ |
| 505 |
"name" => WCPOST_Settings::SETTING_CARRIER_DELIVERY_ENABLED, |
| 506 |
"label" => __("Enable PostNL delivery", "woocommerce-postnl"), |
| 507 |
"type" => "toggle", |
| 508 |
], |
| 509 |
[ |
| 510 |
"name" => WCPOST_Settings::SETTING_CARRIER_DROP_OFF_DAYS, |
| 511 |
"condition" => WCPOST_Settings::SETTING_CARRIER_DELIVERY_ENABLED, |
| 512 |
"label" => __("Drop-off days", "woocommerce-postnl"), |
| 513 |
"callback" => [WCPN_Settings_Callbacks::class, "enhanced_select"], |
| 514 |
"options" => $this->getWeekdays(null), |
| 515 |
"default" => [2], |
| 516 |
"help_text" => __("Days of the week on which you hand over parcels to PostNL", "woocommerce-postnl"), |
| 517 |
], |
| 518 |
[ |
| 519 |
"name" => WCPOST_Settings::SETTING_CARRIER_CUTOFF_TIME, |
| 520 |
"condition" => WCPOST_Settings::SETTING_CARRIER_DELIVERY_ENABLED, |
| 521 |
"label" => __("Cut-off time", "woocommerce-postnl"), |
| 522 |
"help_text" => __( |
| 523 |
"Time at which you stop processing orders for the day (format: hh:mm)", |
| 524 |
"woocommerce-postnl" |
| 525 |
), |
| 526 |
"default" => "17:00", |
| 527 |
], |
| 528 |
[ |
| 529 |
"name" => WCPOST_Settings::SETTING_CARRIER_DROP_OFF_DELAY, |
| 530 |
"condition" => WCPOST_Settings::SETTING_CARRIER_DELIVERY_ENABLED, |
| 531 |
"label" => __("Drop-off delay", "woocommerce-postnl"), |
| 532 |
"type" => "number", |
| 533 |
"max" => 14, |
| 534 |
"help_text" => __("Number of days you need to process an order.", "woocommerce-postnl"), |
| 535 |
], |
| 536 |
[ |
| 537 |
"name" => WCPOST_Settings::SETTING_CARRIER_DELIVERY_DAYS_WINDOW, |
| 538 |
"condition" => WCPOST_Settings::SETTING_CARRIER_DELIVERY_ENABLED, |
| 539 |
"label" => __("Delivery days window", "woocommerce-postnl"), |
| 540 |
"type" => "number", |
| 541 |
"max" => 14, |
| 542 |
"default" => self::ENABLED, |
| 543 |
"help_text" => __( |
| 544 |
"Amount of days a customer can postpone a shipment. Default is 0 days with a maximum value of 14 days.", |
| 545 |
"woocommerce-postnl" |
| 546 |
), |
| 547 |
], |
| 548 |
[ |
| 549 |
"name" => WCPOST_Settings::SETTING_CARRIER_DELIVERY_MORNING_ENABLED, |
| 550 |
"condition" => WCPOST_Settings::SETTING_CARRIER_DELIVERY_ENABLED, |
| 551 |
"label" => __("Morning delivery", "woocommerce-postnl"), |
| 552 |
"type" => "toggle", |
| 553 |
], |
| 554 |
self::getFeeField( |
| 555 |
WCPOST_Settings::SETTING_CARRIER_DELIVERY_MORNING_FEE, |
| 556 |
[ |
| 557 |
WCPOST_Settings::SETTING_CARRIER_DELIVERY_ENABLED, |
| 558 |
WCPOST_Settings::SETTING_CARRIER_DELIVERY_MORNING_ENABLED, |
| 559 |
] |
| 560 |
), |
| 561 |
[ |
| 562 |
"name" => WCPOST_Settings::SETTING_CARRIER_DELIVERY_EVENING_ENABLED, |
| 563 |
"condition" => WCPOST_Settings::SETTING_CARRIER_DELIVERY_ENABLED, |
| 564 |
"label" => __("Evening delivery", "woocommerce-postnl"), |
| 565 |
"type" => "toggle", |
| 566 |
], |
| 567 |
self::getFeeField( |
| 568 |
WCPOST_Settings::SETTING_CARRIER_DELIVERY_EVENING_FEE, |
| 569 |
[ |
| 570 |
WCPOST_Settings::SETTING_CARRIER_DELIVERY_ENABLED, |
| 571 |
WCPOST_Settings::SETTING_CARRIER_DELIVERY_EVENING_ENABLED, |
| 572 |
] |
| 573 |
), |
| 574 |
[ |
| 575 |
"name" => WCPOST_Settings::SETTING_CARRIER_ONLY_RECIPIENT_ENABLED, |
| 576 |
"condition" => WCPOST_Settings::SETTING_CARRIER_DELIVERY_ENABLED, |
| 577 |
"label" => __("shipment_options_only_recipient", "woocommerce-postnl"), |
| 578 |
"type" => "toggle", |
| 579 |
], |
| 580 |
self::getFeeField( |
| 581 |
WCPOST_Settings::SETTING_CARRIER_ONLY_RECIPIENT_FEE, |
| 582 |
[ |
| 583 |
WCPOST_Settings::SETTING_CARRIER_DELIVERY_ENABLED, |
| 584 |
WCPOST_Settings::SETTING_CARRIER_ONLY_RECIPIENT_ENABLED, |
| 585 |
] |
| 586 |
), |
| 587 |
[ |
| 588 |
"name" => WCPOST_Settings::SETTING_CARRIER_SIGNATURE_ENABLED, |
| 589 |
"condition" => WCPOST_Settings::SETTING_CARRIER_DELIVERY_ENABLED, |
| 590 |
"label" => __("shipment_options_signature", "woocommerce-postnl"), |
| 591 |
"type" => "toggle", |
| 592 |
"help_text" => __( |
| 593 |
"Enter an amount that is either positive or negative. For example, do you want to give a discount for using this function or do you want to charge extra for this delivery option.", |
| 594 |
"woocommerce-postnl" |
| 595 |
), |
| 596 |
], |
| 597 |
self::getFeeField( |
| 598 |
WCPOST_Settings::SETTING_CARRIER_SIGNATURE_FEE, |
| 599 |
[ |
| 600 |
WCPOST_Settings::SETTING_CARRIER_DELIVERY_ENABLED, |
| 601 |
WCPOST_Settings::SETTING_CARRIER_SIGNATURE_ENABLED, |
| 602 |
] |
| 603 |
), |
| 604 |
[ |
| 605 |
"name" => WCPOST_Settings::SETTING_CARRIER_MONDAY_DELIVERY_ENABLED, |
| 606 |
"condition" => WCPOST_Settings::SETTING_CARRIER_DELIVERY_ENABLED, |
| 607 |
"label" => __("Monday delivery", "woocommerce-postnl"), |
| 608 |
"type" => "toggle", |
| 609 |
], |
| 610 |
[ |
| 611 |
"name" => WCPOST_Settings::SETTING_CARRIER_SATURDAY_CUTOFF_TIME, |
| 612 |
"condition" => [ |
| 613 |
WCPOST_Settings::SETTING_CARRIER_DELIVERY_ENABLED, |
| 614 |
WCPOST_Settings::SETTING_CARRIER_MONDAY_DELIVERY_ENABLED, |
| 615 |
], |
| 616 |
"class" => ["wcpn__child"], |
| 617 |
"label" => __("Cut-off time on Saturday", "woocommerce-postnl"), |
| 618 |
"placeholder" => "14:30", |
| 619 |
"default" => "15:00", |
| 620 |
"help_text" => __( |
| 621 |
"Time at which you stop processing orders for the day (format: hh:mm)", |
| 622 |
"woocommerce-postnl" |
| 623 |
), |
| 624 |
], |
| 625 |
]; |
| 626 |
} |
| 627 |
|
| 628 |
/** |
| 629 |
* @return array |
| 630 |
*/ |
| 631 |
private function get_section_carrier_postnl_pickup_options(): array |
| 632 |
{ |
| 633 |
return [ |
| 634 |
[ |
| 635 |
"name" => WCPOST_Settings::SETTING_CARRIER_PICKUP_ENABLED, |
| 636 |
"label" => __("Enable PostNL pickup", "woocommerce-postnl"), |
| 637 |
"type" => "toggle", |
| 638 |
], |
| 639 |
self::getFeeField( |
| 640 |
WCPOST_Settings::SETTING_CARRIER_PICKUP_FEE, |
| 641 |
[ |
| 642 |
WCPOST_Settings::SETTING_CARRIER_PICKUP_ENABLED, |
| 643 |
] |
| 644 |
), |
| 645 |
]; |
| 646 |
} |
| 647 |
|
| 648 |
/** |
| 649 |
* @return array |
| 650 |
*/ |
| 651 |
private function get_section_export_defaults_main(): array |
| 652 |
{ |
| 653 |
return [ |
| 654 |
[ |
| 655 |
"name" => WCPOST_Settings::SETTING_SHIPPING_METHODS_PACKAGE_TYPES, |
| 656 |
"label" => __("Package types", "woocommerce-postnl"), |
| 657 |
"callback" => [WCPN_Settings_Callbacks::class, "enhanced_select"], |
| 658 |
"loop" => WCPN_Data::getPackageTypesHuman(), |
| 659 |
"options" => (new WCPN_Shipping_Methods())->getShippingMethods(), |
| 660 |
"default" => [], |
| 661 |
"help_text" => __( |
| 662 |
"Select one or more shipping methods for each PostNL package type", |
| 663 |
"woocommerce-postnl" |
| 664 |
), |
| 665 |
], |
| 666 |
[ |
| 667 |
"name" => WCPOST_Settings::SETTING_CONNECT_PHONE, |
| 668 |
"label" => __("Connect customer phone", "woocommerce-postnl"), |
| 669 |
"type" => "toggle", |
| 670 |
"help_text" => __( |
| 671 |
"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.", |
| 672 |
"woocommerce-postnl" |
| 673 |
), |
| 674 |
], |
| 675 |
[ |
| 676 |
"name" => WCPOST_Settings::SETTING_LABEL_DESCRIPTION, |
| 677 |
"label" => __("Label description", "woocommerce-postnl"), |
| 678 |
"help_text" => __( |
| 679 |
"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. Because of limited space on the label which varies per package type, we recommend that you keep the label description as short as possible.", |
| 680 |
"woocommerce-postnl" |
| 681 |
), |
| 682 |
"append" => $this->getLabelDescriptionAddition(), |
| 683 |
], |
| 684 |
[ |
| 685 |
"name" => WCPOST_Settings::SETTING_EMPTY_PARCEL_WEIGHT, |
| 686 |
"type" => "number", |
| 687 |
"default" => 0, |
| 688 |
"label" => sprintf( |
| 689 |
"%s (%s)", |
| 690 |
__("Empty parcel weight", "woocommerce-postnl"), |
| 691 |
get_option('woocommerce_weight_unit') |
| 692 |
), |
| 693 |
"help_text" => __( |
| 694 |
"Default weight of your empty parcel.", |
| 695 |
"woocommerce-postnl" |
| 696 |
), |
| 697 |
], |
| 698 |
[ |
| 699 |
"name" => WCPOST_Settings::SETTING_HS_CODE, |
| 700 |
"label" => __("Default HS Code", "woocommerce-postnl"), |
| 701 |
"help_text" => __( |
| 702 |
"HS Codes are used for PostNL world shipments, you can find the appropriate code on the site of the Dutch Customs.", |
| 703 |
"woocommerce-postnl" |
| 704 |
), |
| 705 |
], |
| 706 |
[ |
| 707 |
"name" => WCPOST_Settings::SETTING_PACKAGE_CONTENT, |
| 708 |
"label" => __("Customs shipment type", "woocommerce-postnl"), |
| 709 |
"type" => "select", |
| 710 |
"options" => [ |
| 711 |
1 => __("Commercial goods", "woocommerce-postnl"), |
| 712 |
2 => __("Commercial samples", "woocommerce-postnl"), |
| 713 |
3 => __("Documents", "woocommerce-postnl"), |
| 714 |
4 => __("Gifts", "woocommerce-postnl"), |
| 715 |
5 => __("Return shipment", "woocommerce-postnl"), |
| 716 |
], |
| 717 |
], |
| 718 |
[ |
| 719 |
'name' => WCPOST_Settings::SETTING_COUNTRY_OF_ORIGIN, |
| 720 |
'label' => __('setting_country_of_origin', 'woocommerce-postnl'), |
| 721 |
'type' => 'select', |
| 722 |
'options' => (new WC_Countries())->get_countries(), |
| 723 |
'default' => (new WC_Countries())->get_base_country(), |
| 724 |
'help-text' => __( |
| 725 |
'setting_country_of_origin_help_text', |
| 726 |
'woocommerce-postnl' |
| 727 |
), |
| 728 |
], |
| 729 |
// [ |
| 730 |
// "name" => WCPOST_Settings::SETTING_AUTOMATIC_EXPORT, |
| 731 |
// "label" => __("Automatic export", "woocommerce-postnl"), |
| 732 |
// "type" => "toggle", |
| 733 |
// "help_text" => __( |
| 734 |
// "With this setting enabled orders are exported to PostNL automatically after payment.", |
| 735 |
// "woocommerce-postnl" |
| 736 |
// ), |
| 737 |
// ], |
| 738 |
]; |
| 739 |
} |
| 740 |
|
| 741 |
/** |
| 742 |
* @return array |
| 743 |
*/ |
| 744 |
private function get_section_checkout_main(): array |
| 745 |
{ |
| 746 |
return [ |
| 747 |
[ |
| 748 |
"name" => WCPOST_Settings::SETTING_USE_SPLIT_ADDRESS_FIELDS, |
| 749 |
"label" => __("PostNL address fields", "woocommerce-postnl"), |
| 750 |
"type" => "toggle", |
| 751 |
"help_text" => __( |
| 752 |
"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.", |
| 753 |
"woocommerce-postnl" |
| 754 |
), |
| 755 |
], |
| 756 |
[ |
| 757 |
"name" => WCPOST_Settings::SETTING_SHOW_DELIVERY_DAY, |
| 758 |
"label" => __("Show delivery date", "woocommerce-postnl"), |
| 759 |
"type" => "toggle", |
| 760 |
"help_text" => __( |
| 761 |
"Show delivery day options allow your customers to see the delivery day in order confirmation and My Account.", |
| 762 |
"woocommerce-postnl" |
| 763 |
), |
| 764 |
], |
| 765 |
[ |
| 766 |
"name" => WCPOST_Settings::SETTING_DELIVERY_OPTIONS_ENABLED, |
| 767 |
"label" => __("Enable PostNL delivery options", "woocommerce-postnl"), |
| 768 |
"type" => "toggle", |
| 769 |
"help_text" => __( |
| 770 |
"The PostNL delivery options allow your customers to select whether they want their parcel delivered at home or to a pickup point. Depending on the settings you can allow them to select a date, time and even options like requiring a signature on delivery.", |
| 771 |
"woocommerce-postnl" |
| 772 |
), |
| 773 |
], |
| 774 |
[ |
| 775 |
"name" => WCPOST_Settings::SETTINGS_SHOW_DELIVERY_OPTIONS_FOR_BACKORDERS, |
| 776 |
"condition" => WCPOST_Settings::SETTING_DELIVERY_OPTIONS_ENABLED, |
| 777 |
"label" => __("Enable delivery options for backorders", "woocommerce-postnl"), |
| 778 |
"type" => "toggle", |
| 779 |
"help_text" => __( |
| 780 |
"When this option is enabled, delivery options and delivery day will be also shown for backorders.", |
| 781 |
"woocommerce-postnl" |
| 782 |
), |
| 783 |
], |
| 784 |
[ |
| 785 |
"name" => WCPOST_Settings::SETTING_DELIVERY_OPTIONS_DISPLAY, |
| 786 |
"condition" => WCPOST_Settings::SETTING_DELIVERY_OPTIONS_ENABLED, |
| 787 |
"label" => __("settings_checkout_display_for", "woocommerce-postnl"), |
| 788 |
"type" => "select", |
| 789 |
"help_text" => __("settings_checkout_display_for_help_text", "woocommerce-postnl"), |
| 790 |
"options" => [ |
| 791 |
self::DISPLAY_FOR_SELECTED_METHODS => __("settings_checkout_display_for_selected_methods", "woocommerce-postnl"), |
| 792 |
self::DISPLAY_FOR_ALL_METHODS => __("settings_checkout_display_for_all_methods", "woocommerce-postnl"), |
| 793 |
], |
| 794 |
], |
| 795 |
[ |
| 796 |
"name" => WCPOST_Settings::SETTING_DELIVERY_OPTIONS_POSITION, |
| 797 |
"condition" => WCPOST_Settings::SETTING_DELIVERY_OPTIONS_ENABLED, |
| 798 |
"label" => __("Checkout position", "woocommerce-postnl"), |
| 799 |
"type" => "select", |
| 800 |
"default" => "woocommerce_after_checkout_billing_form", |
| 801 |
"options" => [ |
| 802 |
"woocommerce_after_checkout_billing_form" => __( |
| 803 |
"Show after billing details", |
| 804 |
"woocommerce-postnl" |
| 805 |
), |
| 806 |
"woocommerce_after_checkout_shipping_form" => __( |
| 807 |
"Show after shipping details", |
| 808 |
"woocommerce-postnl" |
| 809 |
), |
| 810 |
"woocommerce_checkout_after_customer_details" => __( |
| 811 |
"Show after customer details", |
| 812 |
"woocommerce-postnl" |
| 813 |
), |
| 814 |
"woocommerce_after_order_notes" => __( |
| 815 |
"Show after notes", |
| 816 |
"woocommerce-postnl" |
| 817 |
), |
| 818 |
"woocommerce_review_order_before_payment" => __( |
| 819 |
"Show after subtotal", |
| 820 |
"woocommerce-postnl" |
| 821 |
), |
| 822 |
], |
| 823 |
"help_text" => __( |
| 824 |
"You can change the place of the delivery options on the checkout page. By default it will be placed after shipping details.", |
| 825 |
"woocommerce-postnl" |
| 826 |
), |
| 827 |
], |
| 828 |
[ |
| 829 |
"name" => WCPOST_Settings::SETTING_DELIVERY_OPTIONS_PRICE_FORMAT, |
| 830 |
"condition" => WCPOST_Settings::SETTING_DELIVERY_OPTIONS_ENABLED, |
| 831 |
"label" => __("settings_checkout_price_format", "woocommerce-postnl"), |
| 832 |
"type" => "select", |
| 833 |
"default" => self::DISPLAY_TOTAL_PRICE, |
| 834 |
"options" => [ |
| 835 |
self::DISPLAY_TOTAL_PRICE => __( |
| 836 |
"settings_checkout_total_price", |
| 837 |
"woocommerce-postnl" |
| 838 |
), |
| 839 |
self::DISPLAY_SURCHARGE_PRICE => __( |
| 840 |
"settings_checkout_surcharge", |
| 841 |
"woocommerce-postnl" |
| 842 |
), |
| 843 |
], |
| 844 |
], |
| 845 |
[ |
| 846 |
"name" => WCPOST_Settings::SETTING_PICKUP_LOCATIONS_DEFAULT_VIEW, |
| 847 |
"condition" => WCPOST_Settings::SETTING_DELIVERY_OPTIONS_ENABLED, |
| 848 |
"label" => __("settings_pickup_locations_default_view", "woocommerce-postnl"), |
| 849 |
"type" => "select", |
| 850 |
"default" => self::PICKUP_LOCATIONS_VIEW_MAP, |
| 851 |
"options" => [ |
| 852 |
self::PICKUP_LOCATIONS_VIEW_MAP => __( |
| 853 |
"settings_pickup_locations_default_view_map", |
| 854 |
"woocommerce-postnl" |
| 855 |
), |
| 856 |
self::PICKUP_LOCATIONS_VIEW_LIST => __( |
| 857 |
"settings_pickup_locations_default_view_list", |
| 858 |
"woocommerce-postnl" |
| 859 |
), |
| 860 |
], |
| 861 |
], |
| 862 |
[ |
| 863 |
"name" => WCPOST_Settings::SETTING_DELIVERY_OPTIONS_CUSTOM_CSS, |
| 864 |
"condition" => WCPOST_Settings::SETTING_DELIVERY_OPTIONS_ENABLED, |
| 865 |
"label" => __("Custom styles", "woocommerce-postnl"), |
| 866 |
"type" => "textarea", |
| 867 |
"append" => $this->getCustomCssAddition(), |
| 868 |
"custom_attributes" => [ |
| 869 |
"style" => "font-family: monospace;", |
| 870 |
"rows" => "8", |
| 871 |
"cols" => "12", |
| 872 |
], |
| 873 |
], |
| 874 |
]; |
| 875 |
} |
| 876 |
|
| 877 |
/** |
| 878 |
* Get the weekdays from WP_Locale and remove any entries. Sunday is removed by default unless `null` is passed. |
| 879 |
* |
| 880 |
* @param int|null ...$remove |
| 881 |
* |
| 882 |
* @return array |
| 883 |
*/ |
| 884 |
private function getWeekdays(...$remove): array |
| 885 |
{ |
| 886 |
$weekdays = (new WP_Locale())->weekday; |
| 887 |
|
| 888 |
if ($remove !== null) { |
| 889 |
$remove = count($remove) ? $remove : [0]; |
| 890 |
foreach ($remove as $index) { |
| 891 |
unset($weekdays[$index]); |
| 892 |
} |
| 893 |
} |
| 894 |
|
| 895 |
return $weekdays; |
| 896 |
} |
| 897 |
|
| 898 |
private function get_section_checkout_strings(): array |
| 899 |
{ |
| 900 |
return [ |
| 901 |
[ |
| 902 |
"name" => WCPOST_Settings::SETTING_HEADER_DELIVERY_OPTIONS_TITLE, |
| 903 |
"condition" => WCPOST_Settings::SETTING_DELIVERY_OPTIONS_ENABLED, |
| 904 |
"label" => __("Delivery options title", "woocommerce-postnl"), |
| 905 |
"title" => "Delivery options title", |
| 906 |
"help_text" => __( |
| 907 |
"You can place a delivery title above the PostNL options. When there is no title, it will not be visible.", |
| 908 |
"woocommerce-postnl" |
| 909 |
), |
| 910 |
], |
| 911 |
[ |
| 912 |
"name" => WCPOST_Settings::SETTING_DELIVERY_TITLE, |
| 913 |
"condition" => WCPOST_Settings::SETTING_DELIVERY_OPTIONS_ENABLED, |
| 914 |
"label" => __("Delivery title", "woocommerce-postnl"), |
| 915 |
"default" => __("Delivered at home or at work", "woocommerce-postnl"), |
| 916 |
], |
| 917 |
[ |
| 918 |
"name" => WCPOST_Settings::SETTING_MORNING_DELIVERY_TITLE, |
| 919 |
"condition" => WCPOST_Settings::SETTING_DELIVERY_OPTIONS_ENABLED, |
| 920 |
"label" => __("Morning delivery title", "woocommerce-postnl"), |
| 921 |
"default" => __("Morning delivery", "woocommerce-postnl"), |
| 922 |
], |
| 923 |
[ |
| 924 |
"name" => WCPOST_Settings::SETTING_STANDARD_TITLE, |
| 925 |
"condition" => WCPOST_Settings::SETTING_DELIVERY_OPTIONS_ENABLED, |
| 926 |
"label" => __("Standard delivery title", "woocommerce-postnl"), |
| 927 |
"help_text" => __( |
| 928 |
"When there is no title, the delivery time will automatically be visible.", |
| 929 |
"woocommerce-postnl" |
| 930 |
), |
| 931 |
"default" => __("Standard delivery", "woocommerce-postnl"), |
| 932 |
], |
| 933 |
[ |
| 934 |
"name" => WCPOST_Settings::SETTING_EVENING_DELIVERY_TITLE, |
| 935 |
"condition" => WCPOST_Settings::SETTING_DELIVERY_OPTIONS_ENABLED, |
| 936 |
"label" => __("Evening delivery title", "woocommerce-postnl"), |
| 937 |
"default" => __("Evening delivery", "woocommerce-postnl"), |
| 938 |
], |
| 939 |
[ |
| 940 |
"name" => WCPOST_Settings::SETTING_ONLY_RECIPIENT_TITLE, |
| 941 |
"condition" => WCPOST_Settings::SETTING_DELIVERY_OPTIONS_ENABLED, |
| 942 |
"label" => __("Home address only title", "woocommerce-postnl"), |
| 943 |
"default" => __("shipment_options_only_recipient", "woocommerce-postnl"), |
| 944 |
], |
| 945 |
[ |
| 946 |
"name" => WCPOST_Settings::SETTING_SIGNATURE_TITLE, |
| 947 |
"condition" => WCPOST_Settings::SETTING_DELIVERY_OPTIONS_ENABLED, |
| 948 |
"label" => __("Signature on delivery title", "woocommerce-postnl"), |
| 949 |
"default" => __("shipment_options_signature", "woocommerce-postnl"), |
| 950 |
], |
| 951 |
[ |
| 952 |
"name" => WCPOST_Settings::SETTING_PICKUP_TITLE, |
| 953 |
"condition" => WCPOST_Settings::SETTING_DELIVERY_OPTIONS_ENABLED, |
| 954 |
"label" => __("Pickup title", "woocommerce-postnl"), |
| 955 |
"default" => __("Pickup", "woocommerce-postnl"), |
| 956 |
], |
| 957 |
]; |
| 958 |
} |
| 959 |
|
| 960 |
/** |
| 961 |
* Get the html string to render after the custom css select. |
| 962 |
* |
| 963 |
* @return string |
| 964 |
*/ |
| 965 |
private function getCustomCssAddition(): string |
| 966 |
{ |
| 967 |
$currentTheme = wp_get_theme(); |
| 968 |
|
| 969 |
$preset = sanitize_title($currentTheme); |
| 970 |
$cssPath = WCPOST()->plugin_path() . "/assets/css/delivery-options/delivery-options-preset-$preset.css"; |
| 971 |
|
| 972 |
if (! file_exists($cssPath)) { |
| 973 |
return ""; |
| 974 |
} |
| 975 |
|
| 976 |
return sprintf( |
| 977 |
'<p>%s <a class="" href="#" onclick="document.querySelector(`#delivery_options_custom_css`).value = `%s`">%s</a></p>', |
| 978 |
sprintf(__('Theme "%s" detected.', "woocommerce-postnl"), $currentTheme), |
| 979 |
file_get_contents($cssPath), |
| 980 |
__("Apply preset.", "woocommerce-postnl") |
| 981 |
); |
| 982 |
} |
| 983 |
|
| 984 |
/** |
| 985 |
* Created html for clickable hints for the variables that can be used in the label description. |
| 986 |
* |
| 987 |
* @return string |
| 988 |
*/ |
| 989 |
private function getLabelDescriptionAddition(): string |
| 990 |
{ |
| 991 |
$output = ''; |
| 992 |
$variables = [ |
| 993 |
'[DELIVERY_DATE]' => __('Delivery date', 'woocommerce-postnl'), |
| 994 |
'[ORDER_NR]' => __('Order number', 'woocommerce-postnl'), |
| 995 |
'[PRODUCT_ID]' => __('Product id', 'woocommerce-postnl'), |
| 996 |
'[PRODUCT_NAME]' => __('Product name', 'woocommerce-postnl'), |
| 997 |
'[PRODUCT_QTY]' => __('Product quantity', 'woocommerce-postnl'), |
| 998 |
'[PRODUCT_SKU]' => __('Product SKU', 'woocommerce-postnl'), |
| 999 |
'[CUSTOMER_NOTE]' => __('Customer note', 'woocommerce-postnl'), |
| 1000 |
]; |
| 1001 |
|
| 1002 |
foreach ($variables as $variable => $description) { |
| 1003 |
$output .= "<br><a onclick=\"var el = document.querySelector('#label_description_field input');el.value += '$variable';el.focus();\">$variable</a>: $description"; |
| 1004 |
} |
| 1005 |
|
| 1006 |
return sprintf("<div class=\"label-description-variables\"><p>Available variables: %s</p>", $output); |
| 1007 |
} |
| 1008 |
|
| 1009 |
/** |
| 1010 |
* @param string $name |
| 1011 |
* @param string|array $conditions |
| 1012 |
* |
| 1013 |
* @return array |
| 1014 |
*/ |
| 1015 |
private static function getFeeField(string $name, array $conditions): array |
| 1016 |
{ |
| 1017 |
return [ |
| 1018 |
"name" => $name, |
| 1019 |
"condition" => $conditions, |
| 1020 |
"class" => ["wcpn__child"], |
| 1021 |
"label" => __("Fee (optional)", "woocommerce-postnl"), |
| 1022 |
"type" => "currency", |
| 1023 |
"help_text" => __( |
| 1024 |
"Enter an amount that is either positive or negative. For example, do you want to give a discount for using this function or do you want to charge extra for this delivery option.", |
| 1025 |
"woocommerce-postnl" |
| 1026 |
), |
| 1027 |
]; |
| 1028 |
} |
| 1029 |
} |
| 1030 |
|
| 1031 |
new WCPN_Settings_Data(); |
| 1032 |
|