WordPress at Your Fingertips
function is not described

WC_Cart_Totals::get_shipping_from_cart() protected WC 3.2.0

Get shipping methods from the cart and normalise.

{} It's a method of the class: WC_Cart_Totals{}

No Hooks.

Return

null. Nothing.

Usage

// protected - for code of main (parent) or child class
$result = $this->get_shipping_from_cart();

Changelog

Since 3.2.0 Introduced.

Code of WC_Cart_Totals::get_shipping_from_cart() WC 5.9.0

protected function get_shipping_from_cart() {
	$this->shipping = array();

	if ( ! $this->cart->show_shipping() ) {
		return;
	}

	foreach ( $this->cart->calculate_shipping() as $key => $shipping_object ) {
		$shipping_line            = $this->get_default_shipping_props();
		$shipping_line->object    = $shipping_object;
		$shipping_line->tax_class = get_option( 'woocommerce_shipping_tax_class' );
		$shipping_line->taxable   = true;
		$shipping_line->total     = wc_add_number_precision_deep( $shipping_object->cost );
		$shipping_line->taxes     = wc_add_number_precision_deep( $shipping_object->taxes, false );
		$shipping_line->taxes     = array_map( array( $this, 'round_item_subtotal' ), $shipping_line->taxes );
		$shipping_line->total_tax = array_sum( $shipping_line->taxes );

		$this->shipping[ $key ] = $shipping_line;
	}
}