Skip to content

Commit f4775cc

Browse files
JeroenSormanimikejolley
authored andcommitted
Use shipping method instead of property through magic + doc return statements
1 parent 3c3894b commit f4775cc

23 files changed

+33
-32
lines changed

includes/abstracts/abstract-wc-order.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1731,7 +1731,7 @@ public function get_shipping_to_display( $tax_display = '' ) {
17311731
$shipping = __( 'Free!', 'woocommerce' );
17321732
}
17331733

1734-
return apply_filters( 'woocommerce_order_shipping_to_display', $shipping, $this );
1734+
return apply_filters( 'woocommerce_order_shipping_to_display', $shipping, $this, $tax_display );
17351735
}
17361736

17371737
/**

includes/abstracts/abstract-wc-shipping-method.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ public function get_title() {
224224
* Return calculated rates for a package.
225225
*
226226
* @since 2.6.0
227-
* @param object $package Package array.
227+
* @param array $package Package array.
228228
* @return array
229229
*/
230230
public function get_rates_for_package( $package ) {

includes/admin/meta-boxes/views/html-order-items.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
</tbody>
6767
<tbody id="order_shipping_line_items">
6868
<?php
69-
$shipping_methods = WC()->shipping() ? WC()->shipping->load_shipping_methods() : array();
69+
$shipping_methods = WC()->shipping() ? WC()->shipping()->load_shipping_methods() : array();
7070
foreach ( $line_items_shipping as $item_id => $item ) {
7171
include 'html-order-shipping.php';
7272
}

includes/admin/settings/class-wc-settings-shipping.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function get_sections() {
5151

5252
if ( ! defined( 'WC_INSTALLING' ) ) {
5353
// Load shipping methods so we can show any global options they may have.
54-
$shipping_methods = WC()->shipping->load_shipping_methods();
54+
$shipping_methods = WC()->shipping()->load_shipping_methods();
5555

5656
foreach ( $shipping_methods as $method ) {
5757
if ( ! $method->has_settings() ) {
@@ -146,7 +146,7 @@ public function output() {
146146
global $current_section, $hide_save_button;
147147

148148
// Load shipping methods so we can show any global options they may have.
149-
$shipping_methods = WC()->shipping->load_shipping_methods();
149+
$shipping_methods = WC()->shipping()->load_shipping_methods();
150150

151151
if ( '' === $current_section ) {
152152
$this->output_zones_screen();

includes/admin/settings/views/html-admin-page-shipping-zone-methods.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@
183183

184184
<select name="add_method_id">
185185
<?php
186-
foreach ( WC()->shipping->load_shipping_methods() as $method ) {
186+
foreach ( WC()->shipping()->load_shipping_methods() as $method ) {
187187
if ( ! $method->supports( 'shipping-zones' ) ) {
188188
continue;
189189
}

includes/admin/settings/views/html-admin-page-shipping-zones.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104

105105
<select name="add_method_id">
106106
<?php
107-
foreach ( WC()->shipping->load_shipping_methods() as $method ) {
107+
foreach ( WC()->shipping()->load_shipping_methods() as $method ) {
108108
if ( ! $method->supports( 'shipping-zones' ) ) {
109109
continue;
110110
}

includes/class-wc-ajax.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -978,7 +978,7 @@ public static function add_order_shipping() {
978978
$order_id = absint( $_POST['order_id'] );
979979
$order = wc_get_order( $order_id );
980980
$order_taxes = $order->get_taxes();
981-
$shipping_methods = WC()->shipping() ? WC()->shipping->load_shipping_methods() : array();
981+
$shipping_methods = WC()->shipping() ? WC()->shipping()->load_shipping_methods() : array();
982982

983983
// Add new shipping
984984
$item = new WC_Order_Item_Shipping();

includes/class-wc-cart.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -1226,7 +1226,7 @@ public function needs_payment() {
12261226
* Uses the shipping class to calculate shipping then gets the totals when its finished.
12271227
*/
12281228
public function calculate_shipping() {
1229-
$this->shipping_methods = $this->needs_shipping() ? $this->get_chosen_shipping_methods( WC()->shipping->calculate_shipping( $this->get_shipping_packages() ) ) : array();
1229+
$this->shipping_methods = $this->needs_shipping() ? $this->get_chosen_shipping_methods( WC()->shipping()->calculate_shipping( $this->get_shipping_packages() ) ) : array();
12301230

12311231
$shipping_taxes = wp_list_pluck( $this->shipping_methods, 'taxes' );
12321232
$merged_taxes = array();
@@ -1604,7 +1604,7 @@ public function apply_coupon( $coupon_code ) {
16041604

16051605
// Choose free shipping.
16061606
if ( $the_coupon->get_free_shipping() ) {
1607-
$packages = WC()->shipping->get_packages();
1607+
$packages = WC()->shipping()->get_packages();
16081608
$chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' );
16091609

16101610
foreach ( $packages as $i => $package ) {

includes/class-wc-checkout.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ public function create_order( $data ) {
350350
$order->set_total( WC()->cart->get_total( 'edit' ) );
351351
$this->create_order_line_items( $order, WC()->cart );
352352
$this->create_order_fee_lines( $order, WC()->cart );
353-
$this->create_order_shipping_lines( $order, WC()->session->get( 'chosen_shipping_methods' ), WC()->shipping->get_packages() );
353+
$this->create_order_shipping_lines( $order, WC()->session->get( 'chosen_shipping_methods' ), WC()->shipping()->get_packages() );
354354
$this->create_order_tax_lines( $order, WC()->cart );
355355
$this->create_order_coupon_lines( $order, WC()->cart );
356356

@@ -774,7 +774,7 @@ protected function validate_checkout( &$data, &$errors ) {
774774
} else {
775775
$chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' );
776776

777-
foreach ( WC()->shipping->get_packages() as $i => $package ) {
777+
foreach ( WC()->shipping()->get_packages() as $i => $package ) {
778778
if ( ! isset( $chosen_shipping_methods[ $i ], $package['rates'][ $chosen_shipping_methods[ $i ] ] ) ) {
779779
$errors->add( 'shipping', __( 'No shipping method has been selected. Please double check your address, or contact us if you need any help.', 'woocommerce' ) );
780780
}

includes/class-wc-emails.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class WC_Emails {
1818
/**
1919
* Array of email notification classes
2020
*
21-
* @var array
21+
* @var WC_Email[]
2222
*/
2323
public $emails = array();
2424

@@ -231,7 +231,7 @@ public function init() {
231231
/**
232232
* Return the email classes - used in admin to load settings.
233233
*
234-
* @return array
234+
* @return WC_Email[]
235235
*/
236236
public function get_emails() {
237237
return $this->emails;

includes/class-wc-shipping.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public function get_shipping_method_class_names() {
151151
* If a $package is passed some methods may add themselves conditionally and zones will be used.
152152
*
153153
* @param array $package Package information.
154-
* @return array
154+
* @return WC_Shipping_Method[]
155155
*/
156156
public function load_shipping_methods( $package = array() ) {
157157
if ( ! empty( $package ) ) {
@@ -209,7 +209,7 @@ public function unregister_shipping_methods() {
209209
/**
210210
* Returns all registered shipping methods for usage.
211211
*
212-
* @return array
212+
* @return WC_Shipping_Method[]
213213
*/
214214
public function get_shipping_methods() {
215215
if ( is_null( $this->shipping_methods ) ) {

includes/class-wc-tracker.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ private static function get_active_payment_gateways() {
401401
*/
402402
private static function get_active_shipping_methods() {
403403
$active_methods = array();
404-
$shipping_methods = WC()->shipping->get_shipping_methods();
404+
$shipping_methods = WC()->shipping()->get_shipping_methods();
405405
foreach ( $shipping_methods as $id => $shipping_method ) {
406406
if ( isset( $shipping_method->enabled ) && 'yes' === $shipping_method->enabled ) {
407407
$active_methods[ $id ] = array(

includes/gateways/cod/class-wc-gateway-cod.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ private function get_canonical_order_shipping_item_rate_ids( $order_shipping_ite
237237
*/
238238
private function get_canonical_package_rate_ids( $chosen_package_rate_ids ) {
239239

240-
$shipping_packages = WC()->shipping->get_packages();
240+
$shipping_packages = WC()->shipping()->get_packages();
241241
$canonical_rate_ids = array();
242242

243243
if ( ! empty( $chosen_package_rate_ids ) && is_array( $chosen_package_rate_ids ) ) {

includes/shipping/flat-rate/class-wc-shipping-flat-rate.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public function calculate_shipping( $package = array() ) {
159159
}
160160

161161
// Add shipping class costs.
162-
$shipping_classes = WC()->shipping->get_shipping_classes();
162+
$shipping_classes = WC()->shipping()->get_shipping_classes();
163163

164164
if ( ! empty( $shipping_classes ) ) {
165165
$found_shipping_classes = $this->find_shipping_classes( $package );

includes/shipping/flat-rate/includes/settings-flat-rate.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
),
3939
);
4040

41-
$shipping_classes = WC()->shipping->get_shipping_classes();
41+
$shipping_classes = WC()->shipping()->get_shipping_classes();
4242

4343
if ( ! empty( $shipping_classes ) ) {
4444
$settings['class_costs'] = array(

includes/shipping/legacy-flat-rate/includes/settings-flat-rate.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
),
7070
);
7171

72-
$shipping_classes = WC()->shipping->get_shipping_classes();
72+
$shipping_classes = WC()->shipping()->get_shipping_classes();
7373

7474
if ( ! empty( $shipping_classes ) ) {
7575
$settings['class_costs'] = array(

includes/shortcodes/class-wc-shortcode-cart.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class WC_Shortcode_Cart {
2222
*/
2323
public static function calculate_shipping() {
2424
try {
25-
WC()->shipping->reset_shipping();
25+
WC()->shipping()->reset_shipping();
2626

2727
$address = array();
2828

includes/wc-cart-functions.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ function wc_cart_totals_subtotal_html() {
203203
* Get shipping methods.
204204
*/
205205
function wc_cart_totals_shipping_html() {
206-
$packages = WC()->shipping->get_packages();
206+
$packages = WC()->shipping()->get_packages();
207207
$first = true;
208208

209209
foreach ( $packages as $i => $package ) {

includes/wc-core-functions.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -1285,7 +1285,7 @@ function wc_get_checkout_url() {
12851285
* @param string|object $shipping_method class name (string) or a class object.
12861286
*/
12871287
function woocommerce_register_shipping_method( $shipping_method ) {
1288-
WC()->shipping->register_shipping_method( $shipping_method );
1288+
WC()->shipping()->register_shipping_method( $shipping_method );
12891289
}
12901290

12911291
if ( ! function_exists( 'wc_get_shipping_zone' ) ) {
@@ -1456,7 +1456,7 @@ function wc_get_shipping_method_count( $include_legacy = false ) {
14561456

14571457
if ( $include_legacy ) {
14581458
// Count activated methods that don't support shipping zones.
1459-
$methods = WC()->shipping->get_shipping_methods();
1459+
$methods = WC()->shipping()->get_shipping_methods();
14601460

14611461
foreach ( $methods as $method ) {
14621462
if ( isset( $method->enabled ) && 'yes' === $method->enabled && ! $method->supports( 'shipping-zones' ) ) {

includes/wc-term-functions.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ function wc_terms_clauses( $clauses, $taxonomies, $args ) {
541541
* Function for recounting product terms, ignoring hidden products.
542542
*
543543
* @param array $terms List of terms.
544-
* @param string $taxonomy Taxonomy.
544+
* @param object $taxonomy Taxonomy.
545545
* @param bool $callback Callback.
546546
* @param bool $terms_are_term_taxonomy_ids If terms are from term_taxonomy_id column.
547547
*/

includes/wc-update-functions.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -738,8 +738,9 @@ function wc_update_240_shipping_methods() {
738738
foreach ( $shipping_methods as $flat_rate_option_key => $shipping_method ) {
739739
// Stop this running more than once if routine is repeated.
740740
if ( version_compare( $shipping_method->get_option( 'version', 0 ), '2.4.0', '<' ) ) {
741-
$has_classes = count( WC()->shipping->get_shipping_classes() ) > 0;
742-
$cost_key = $has_classes ? 'no_class_cost' : 'cost';
741+
$shipping_classes = WC()->shipping()->get_shipping_classes();
742+
$has_classes = count( $shipping_classes ) > 0;
743+
$cost_key = $has_classes ? 'no_class_cost': 'cost';
743744
$min_fee = $shipping_method->get_option( 'minimum_fee' );
744745
$math_cost_strings = array(
745746
'cost' => array(),
@@ -753,7 +754,7 @@ function wc_update_240_shipping_methods() {
753754
$math_cost_strings[ $cost_key ][] = strstr( $fee, '%' ) ? '[fee percent="' . str_replace( '%', '', $fee ) . '" min="' . esc_attr( $min_fee ) . '"]' : $fee;
754755
}
755756

756-
foreach ( WC()->shipping->get_shipping_classes() as $shipping_class ) {
757+
foreach ( $shipping_classes as $shipping_class ) {
757758
$rate_key = 'class_cost_' . $shipping_class->slug;
758759
$math_cost_strings[ $rate_key ] = $math_cost_strings['no_class_cost'];
759760
}

tests/framework/helpers/class-wc-helper-shipping.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public static function create_simple_flat_rate() {
2525
update_option( 'woocommerce_flat_rate_settings', $flat_rate_settings );
2626
update_option( 'woocommerce_flat_rate', array() );
2727
WC_Cache_Helper::get_transient_version( 'shipping', true );
28-
WC()->shipping->load_shipping_methods();
28+
WC()->shipping()->load_shipping_methods();
2929
}
3030

3131
/**
@@ -37,6 +37,6 @@ public static function delete_simple_flat_rate() {
3737
delete_option( 'woocommerce_flat_rate_settings' );
3838
delete_option( 'woocommerce_flat_rate' );
3939
WC_Cache_Helper::get_transient_version( 'shipping', true );
40-
WC()->shipping->unregister_shipping_methods();
40+
WC()->shipping()->unregister_shipping_methods();
4141
}
4242
}

tests/unit-tests/cart/cart.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ public function test_inclusive_tax_rounding() {
675675
update_option( 'woocommerce_flat_rate_settings', $flat_rate_settings );
676676
update_option( 'woocommerce_flat_rate', array() );
677677
WC_Cache_Helper::get_transient_version( 'shipping', true );
678-
WC()->shipping->load_shipping_methods();
678+
WC()->shipping()->load_shipping_methods();
679679

680680
// Create the product and add it to the cart.
681681
$product = new WC_Product_Simple();

0 commit comments

Comments
 (0)