wc_get_default_shipping_method_for_package( int $key, array $package, string $chosen_method )
Choose the default method for a package.
Description Description
Parameters Parameters
- $key
-
(Required) Key of package.
- $package
-
(Required) Package data array.
- $chosen_method
-
(Required) Chosen method id.
Return Return
(string)
Source Source
File: includes/wc-cart-functions.php
function wc_get_default_shipping_method_for_package( $key, $package, $chosen_method ) {
$rate_keys = array_keys( $package['rates'] );
$default = current( $rate_keys );
$coupons = WC()->cart->get_coupons();
foreach ( $coupons as $coupon ) {
if ( $coupon->get_free_shipping() ) {
foreach ( $rate_keys as $rate_key ) {
if ( 0 === stripos( $rate_key, 'free_shipping' ) ) {
$default = $rate_key;
break;
}
}
break;
}
}
return apply_filters( 'woocommerce_shipping_chosen_method', $default, $package['rates'], $chosen_method );
}
Changelog Changelog
| Version | Description |
|---|---|
| 3.2.0 | Introduced. |