1 | <?php |
||
16 | class WC_Shipping_Free_Shipping extends WC_Shipping_Method { |
||
17 | |||
18 | /** @var float Min amount to be valid */ |
||
19 | public $min_amount = 0; |
||
20 | |||
21 | /** @var string Requires option */ |
||
22 | public $requires = ''; |
||
23 | |||
24 | /** |
||
25 | * Constructor. |
||
26 | */ |
||
27 | public function __construct( $instance_id = 0 ) { |
||
43 | |||
44 | /** |
||
45 | * Get setting form fields for instances of this shipping method within zones. |
||
46 | * @return array |
||
47 | */ |
||
48 | public function get_instance_form_fields() { |
||
92 | |||
93 | /** |
||
94 | * See if free shipping is available based on the package and cart. |
||
95 | * @param array $package |
||
96 | * @return bool |
||
97 | */ |
||
98 | public function is_available( $package ) { |
||
99 | $has_coupon = false; |
||
100 | $has_met_min_amount = false; |
||
101 | |||
102 | if ( in_array( $this->requires, array( 'coupon', 'either', 'both' ) ) ) { |
||
103 | if ( $coupons = WC()->cart->get_coupons() ) { |
||
104 | foreach ( $coupons as $code => $coupon ) { |
||
105 | if ( $coupon->is_valid() && $coupon->enable_free_shipping() ) { |
||
106 | $has_coupon = true; |
||
107 | break; |
||
108 | } |
||
109 | } |
||
110 | } |
||
111 | } |
||
112 | |||
113 | if ( in_array( $this->requires, array( 'min_amount', 'either', 'both' ) ) && isset( WC()->cart->cart_contents_total ) ) { |
||
114 | $total = WC()->cart->get_displayed_subtotal(); |
||
115 | |||
116 | if ( $total >= $this->min_amount ) { |
||
117 | $has_met_min_amount = true; |
||
118 | } |
||
119 | } |
||
120 | |||
121 | switch ( $this->requires ) { |
||
122 | case 'min_amount' : |
||
123 | $is_available = $has_met_min_amount; |
||
124 | break; |
||
125 | case 'coupon' : |
||
126 | $is_available = $has_coupon; |
||
127 | break; |
||
128 | case 'both' : |
||
129 | $is_available = $has_met_min_amount && $has_coupon; |
||
130 | break; |
||
131 | case 'either' : |
||
132 | $is_available = $has_met_min_amount || $has_coupon; |
||
133 | break; |
||
134 | default : |
||
135 | $is_available = true; |
||
136 | break; |
||
137 | } |
||
138 | |||
139 | return apply_filters( 'woocommerce_shipping_' . $this->id . '_is_available', $is_available, $package ); |
||
140 | } |
||
141 | |||
142 | /** |
||
143 | * Called to calculate shipping rates for this method. Rates can be added using the add_rate() method. |
||
144 | * @uses WC_Shipping_Method::add_rate() |
||
145 | */ |
||
146 | public function calculate_shipping( $package = array() ) { |
||
154 | } |
||
155 |
This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.
Unreachable code is most often the result of
return
,die
orexit
statements that have been added for debug purposes.In the above example, the last
return false
will never be executed, because a return statement has already been met in every possible execution path.