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.


Top ↑

Return Return

(string)


Top ↑

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 );
}

Top ↑

Changelog Changelog

Changelog
Version Description
3.2.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.