Automattic\WooCommerce\StoreApi\Utilities

CartController::select_shipping_rate()publicWC 1.0

Selects a shipping rate.

Method of the class: CartController{}

No Hooks.

Return

null. Nothing (null).

Usage

$CartController = new CartController();
$CartController->select_shipping_rate( $package_id, $rate_id );
$package_id(int|string) (required)
ID of the package to choose a rate for.
$rate_id(string) (required)
ID of the rate being chosen.

CartController::select_shipping_rate() code WC 8.9.0

public function select_shipping_rate( $package_id, $rate_id ) {
	if ( ! is_string( $rate_id ) ) {
		return;
	}
	$cart                        = $this->get_cart_instance();
	$session_data                = wc()->session->get( 'chosen_shipping_methods' ) ? wc()->session->get( 'chosen_shipping_methods' ) : [];
	$session_data[ $package_id ] = $rate_id;

	wc()->session->set( 'chosen_shipping_methods', $session_data );
}