WC_Checkout::get_value()
Gets the value either from POST, or from the customer object. Sets the default values in checkout fields.
Method of the class: WC_Checkout{}
Hooks from the method
Return
String
. The default value.
Usage
$WC_Checkout = new WC_Checkout(); $WC_Checkout->get_value( $input );
- $input(string) (required)
- Name of the input we want to grab data for. e.g. billing_country.
WC_Checkout::get_value() WC Checkout::get value code WC 9.5.1
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 ( is_callable( array( $customer_object, 'meta_exists' ) ) && $customer_object->meta_exists( $input ) ) { $value = $customer_object->get_meta( $input, true ); } if ( '' === $value ) { $value = null; } return apply_filters( 'default_checkout_' . $input, $value, $input ); }