Automattic\WooCommerce\Blocks\Domain\Services

CheckoutFields::get_field_from_object()publicWC 1.0

Returns a field value for a given object.

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

Хуки из метода

Возвращает

Разное. The field value.

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

$CheckoutFields = new CheckoutFields();
$CheckoutFields->get_field_from_object( $key, $wc_object, $group );
$key(строка) (обязательный)
The field key.
$wc_object(WC_Customer|WC_Order) (обязательный)
The customer or order to get the field value for.
$group(строка)
The group to get the field value for (shipping|billing|other).
По умолчанию: 'other'

Код CheckoutFields::get_field_from_object() WC 9.6.1

public function get_field_from_object( string $key, WC_Data $wc_object, string $group = 'other' ) {
	if ( 'additional' === $group ) {
		wc_deprecated_argument( 'group', '8.9.0', 'The "additional" group is deprecated. Use "other" instead.' );
		$group = 'other';
	}

	$meta_key = self::get_group_key( $group ) . $key;

	$value = $wc_object->get_meta( $meta_key, true );

	if ( ! $value && '0' !== $value ) {
		/**
		 * Allow providing a default value for additional fields if no value is already set.
		 *
		 * @param null $value The default value for the filter, always null.
		 * @param string $group The group of this key (shipping|billing|other).
		 * @param WC_Data $wc_object The object to get the field value for.
		 *
		 * @since 8.9.0
		 */
		$value = apply_filters( "woocommerce_get_default_value_for_{$key}", null, $group, $wc_object );
	}

	// We cast the value to a boolean if the field is a checkbox.
	if ( $this->is_field( $key ) && 'checkbox' === $this->additional_fields[ $key ]['type'] ) {
		return '1' === $value;
	}

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

	return $value;
}