WC_Checkout::get_value( string $input )
Gets the value either from POST, or from the customer object. Sets the default values in checkout fields.
Description Description
Parameters Parameters
- $input
-
(Required) Name of the input we want to grab data for. e.g. billing_country.
Return Return
(string) The default value.
Source Source
File: includes/class-wc-checkout.php
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 ] ) ) { // WPCS: input var ok, CSRF OK. return wc_clean( wp_unslash( $_POST[ $input ] ) ); // WPCS: input var ok, CSRF OK. } // 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 ); }