WC_Checkout::get_value()publicWC 1.0

Gets the value either from POST, or from the customer object. Sets the default values in checkout fields.

Метод класса: WC_Checkout{}

Возвращает

Строку. The default value.

Использование

$WC_Checkout = new WC_Checkout();
$WC_Checkout->get_value( $input );
$input(строка) (обязательный)
Name of the input we want to grab data for. e.g. billing_country.

Код WC_Checkout::get_value() WC 8.7.0

public function get_value( $input ) {
	// If the form was posted, get the posted value. This will only tend to happen when JavaScript is disabled client side.
	if ( ! empty( $_POST[ $input ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
		return wc_clean( wp_unslash( $_POST[ $input ] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
	}

	// Allow 3rd parties to short circuit the logic and return their own default value.
	$value = apply_filters( 'woocommerce_checkout_get_value', null, $input );

	if ( ! is_null( $value ) ) {
		return $value;
	}

	/**
	 * For logged in customers, pull data from their account rather than the session which may contain incomplete data.
	 * Another reason is that WC sets shipping address to the billing address on the checkout updates unless the
	 * "ship to another address" box is checked. @see issue #20975.
	 */
	$customer_object = false;

	if ( is_user_logged_in() ) {
		// Load customer object, but keep it cached to avoid reloading it multiple times.
		if ( is_null( $this->logged_in_customer ) ) {
			$this->logged_in_customer = new WC_Customer( get_current_user_id(), true );
		}
		$customer_object = $this->logged_in_customer;
	}

	if ( ! $customer_object ) {
		$customer_object = WC()->customer;
	}

	if ( is_callable( array( $customer_object, "get_$input" ) ) ) {
		$value = $customer_object->{"get_$input"}();
	} elseif ( $customer_object->meta_exists( $input ) ) {
		$value = $customer_object->get_meta( $input, true );
	}

	if ( '' === $value ) {
		$value = null;
	}

	return apply_filters( 'default_checkout_' . $input, $value, $input );
}