|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
namespace Wordlift\Shipping_Data; |
|
5
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
use WC_Shipping_Method; |
|
8
|
|
|
|
|
9
|
|
|
class Shipping_Method { |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* @var WC_Shipping_Method $wc_shipping_method |
|
13
|
|
|
*/ |
|
14
|
|
|
protected $wc_shipping_method; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Shipping_Method constructor. |
|
18
|
|
|
* |
|
19
|
|
|
* @param WC_Shipping_Method $wc_shipping_method |
|
20
|
|
|
*/ |
|
21
|
|
|
public function __construct( $wc_shipping_method ) { |
|
22
|
|
|
$this->wc_shipping_method = $wc_shipping_method; |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @param WC_Shipping_Method $wc_shipping_method |
|
27
|
|
|
* |
|
28
|
|
|
* @return Shipping_Method |
|
29
|
|
|
*/ |
|
30
|
|
|
public static function from_wc_shipping_method( $wc_shipping_method ) { |
|
31
|
|
|
|
|
32
|
|
|
switch ( get_class( $wc_shipping_method ) ) { |
|
33
|
|
|
case 'WC_Shipping_Local_Pickup': |
|
34
|
|
|
return new Local_Pickup_Shipping_Method( $wc_shipping_method ); |
|
35
|
|
|
|
|
36
|
|
|
case 'WC_Shipping_Flat_Rate': |
|
37
|
|
|
return new Flat_Rate_Shipping_Method( $wc_shipping_method ); |
|
38
|
|
|
|
|
39
|
|
|
case 'WC_Shipping_Free_Shipping': |
|
40
|
|
|
return new Free_Shipping_Shipping_Method( $wc_shipping_method ); |
|
41
|
|
|
|
|
42
|
|
|
default: |
|
43
|
|
|
return new self( $wc_shipping_method ); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function add_available_delivery_method( &$jsonld ) { |
|
49
|
|
|
|
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function add_shipping_rate( &$offer_shipping_details ) { |
|
53
|
|
|
|
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function add_transit_time( &$shipping_delivery_time ) { |
|
57
|
|
|
|
|
58
|
|
|
$prefix = "wcsdt_transit_m{$this->wc_shipping_method->get_instance_id()}"; |
|
59
|
|
|
$property = 'transitTime'; |
|
60
|
|
|
|
|
61
|
|
|
$option = get_option( 'wpsso_options' ); |
|
62
|
|
|
|
|
63
|
|
|
if ( empty( $option["{$prefix}_unit_code"] ) |
|
64
|
|
|
|| empty( $option["{$prefix}_minimum"] ) |
|
65
|
|
|
|| empty( $option["{$prefix}_maximum"] ) ) { |
|
66
|
|
|
return; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
$unit_code = $option["{$prefix}_unit_code"]; |
|
70
|
|
|
$minimum = $option["{$prefix}_minimum"]; |
|
71
|
|
|
$maximum = $option["{$prefix}_maximum"]; |
|
72
|
|
|
|
|
73
|
|
View Code Duplication |
if ( 'HUR' === $unit_code ) { |
|
|
|
|
|
|
74
|
|
|
$minimum = floor( $minimum / 24.0 ); |
|
75
|
|
|
$maximum = ceil( $maximum / 24.0 ); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
$shipping_delivery_time[ $property ] = array( |
|
79
|
|
|
'@type' => 'QuantitativeValue', |
|
80
|
|
|
'minValue' => intval( $minimum ), |
|
81
|
|
|
'maxValue' => intval( $maximum ), |
|
82
|
|
|
); |
|
83
|
|
|
|
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.