WC_Cart::show_shipping()publicWC 1.0

Sees if the customer has entered enough data to calc the shipping yet.

Method of the class: WC_Cart{}

Return

true|false.

Usage

$WC_Cart = new WC_Cart();
$WC_Cart->show_shipping();

WC_Cart::show_shipping() code WC 8.9.0

public function show_shipping() {
	if ( ! wc_shipping_enabled() || ! $this->get_cart_contents() ) {
		return false;
	}

	if ( 'yes' === get_option( 'woocommerce_shipping_cost_requires_address' ) ) {
		$country = $this->get_customer()->get_shipping_country();
		if ( ! $country ) {
			return false;
		}
		$country_fields = WC()->countries->get_address_fields( $country, 'shipping_' );
		/**
		 * Filter to not require shipping state for shipping calculation, even if it is required at checkout.
		 * This can be used to allow shipping calculations to be done without a state.
		 *
		 * @since 8.4.0
		 *
		 * @param bool $show_state Whether to use the state field. Default true.
		 */
		$state_enabled  = apply_filters( 'woocommerce_shipping_calculator_enable_state', true );
		$state_required = isset( $country_fields['shipping_state'] ) && $country_fields['shipping_state']['required'];
		if ( $state_enabled && $state_required && ! $this->get_customer()->get_shipping_state() ) {
			return false;
		}
		/**
		 * Filter to not require shipping postcode for shipping calculation, even if it is required at checkout.
		 * This can be used to allow shipping calculations to be done without a postcode.
		 *
		 * @since 8.4.0
		 *
		 * @param bool $show_postcode Whether to use the postcode field. Default true.
		 */
		$postcode_enabled  = apply_filters( 'woocommerce_shipping_calculator_enable_postcode', true );
		$postcode_required = isset( $country_fields['shipping_postcode'] ) && $country_fields['shipping_postcode']['required'];
		if ( $postcode_enabled && $postcode_required && ! $this->get_customer()->get_shipping_postcode() ) {
			return false;
		}
	}

	return apply_filters( 'woocommerce_cart_ready_to_calc_shipping', true );
}