PluginProbe
Packeta / 1.2.6
Packeta v1.2.6
2.3.2 2.3.1 trunk 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3.0 1.3.1 1.3.2 1.4 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 All 56 releases
packeta / src / Packetery / Module / Carrier / Options.php

Options.php in Packeta 1.2.6, at src/Packetery/Module/Carrier/Options.php

68 lines 1.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Options class.
4 *
5 * @package Packetery
6 */
7
8 declare( strict_types=1 );
9
10
11 namespace Packetery\Module\Carrier;
12
13 use Packetery\Module\Checkout;
14
15 /**
16 * Options class.
17 */
18 class Options {
19
20 /**
21 * Options.
22 *
23 * @var array
24 */
25 private $options;
26
27 /**
28 * Constructor.
29 *
30 * @param array $options Options.
31 */
32 public function __construct( array $options ) {
33 $this->options = $options;
34 }
35
36 /**
37 * Carrier ID.
38 *
39 * @param string $carrierId Carrier ID.
40 *
41 * @return static
42 */
43 public static function createByCarrierId( string $carrierId ): self {
44 $optionId = Checkout::CARRIER_PREFIX . $carrierId;
45 $options = get_option( $optionId );
46 if ( empty( $options ) ) {
47 $options = [];
48 }
49
50 return new self( $options );
51 }
52
53 /**
54 * Gets type of address validation. One of ['required', 'optional', 'none'].
55 *
56 * @return string
57 */
58 public function getAddressValidation(): string {
59 $none = 'none';
60 $value = $this->options['address_validation'] ?? $none;
61 if ( $value ) {
62 return $value;
63 }
64
65 return $none;
66 }
67 }
68