WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru

woocommerce_checkout_fields хук-фильтр . WC 1.0

Позволяет изменить набор полей и их свойства в формах на странице оформления заказа.

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

add_filter( 'woocommerce_checkout_fields', 'filter_function_name_72' );
function filter_function_name_72( $fields ){
	// Изменяем...

	return $fields;
}
$fields
Массив полей.

Пример данных в $fields:

Array(
	[billing] => Array(
			[billing_first_name] => Array(
					[label] => Имя
					[required] => 1
					[class] => Array(
							[0] => form-row-first
					)
					[autocomplete] => given-name
					[priority] => 10
			)

			[billing_last_name] => Array(
					[label] => Фамилия
					[required] => 1
					[class] => Array(
							[0] => form-row-last
					)
					[autocomplete] => family-name
					[priority] => 20
			)

			[billing_company] => Array(
					[label] => Название компании
					[class] => Array(
							[0] => form-row-wide
					)
					[autocomplete] => organization
					[priority] => 30
					[required] => 
			)

			[billing_country] => Array(
					[type] => country
					[label] => Страна
					[required] => 1
					[class] => Array(
							[0] => form-row-wide
							[1] => address-field
							[2] => update_totals_on_change
					)
					[autocomplete] => country
					[priority] => 40
			)

			[billing_address_1] => Array
				(
					[label] => Адрес
					[placeholder] => Номер дома и название улицы
					[required] => 1
					[class] => Array(
							[0] => form-row-wide
							[1] => address-field
					)
					[autocomplete] => address-line1
					[priority] => 50
			)

			[billing_address_2] => Array(
					[placeholder] => Дополнительные сведения об адресе (необязательно)
					[class] => Array(
							[0] => form-row-wide
							[1] => address-field
					)
					[autocomplete] => address-line2
					[priority] => 60
					[required] => 
			)

			[billing_city] => Array(
					[label] => Населённый пункт
					[required] => 1
					[class] => Array(
							[0] => form-row-wide
							[1] => address-field
					)
					[autocomplete] => address-level2
					[priority] => 70
			)

			[billing_state] => Array(
					[type] => state
					[label] => Область / район
					[required] => 1
					[class] => Array(
							[0] => form-row-wide
							[1] => address-field
					)
					[validate] => Array(
							[0] => state
					)
					[autocomplete] => address-level1
					[priority] => 80
					[country_field] => billing_country
					[country] => RU
			)

			[billing_postcode] => Array(
					[label] => Почтовый индекс
					[required] => 1
					[class] => Array(
							[0] => form-row-wide
							[1] => address-field
					)
					[validate] => Array(
							[0] => postcode
					)
					[autocomplete] => postal-code
					[priority] => 90
			)

			[billing_phone] => Array(
					[label] => Телефон
					[required] => 1
					[type] => tel
					[class] => Array(
							[0] => form-row-wide
					)
					[validate] => Array(
							[0] => phone
					)
					[autocomplete] => tel
					[priority] => 100
			)

			[billing_email] => Array(
					[label] => Email
					[required] => 1
					[type] => email
					[class] => Array(
							[0] => form-row-wide
					)
					[validate] => Array(
							[0] => email
					)
					[autocomplete] => email username
					[priority] => 110
			)

	)

	[shipping] => Array(
			[shipping_first_name] => Array(
					[label] => Имя
					[required] => 1
					[class] => Array(
							[0] => form-row-first
					)
					[autocomplete] => given-name
					[priority] => 10
			)

			[shipping_last_name] => Array(
					[label] => Фамилия
					[required] => 1
					[class] => Array(
							[0] => form-row-last
					)
					[autocomplete] => family-name
					[priority] => 20
			)

			[shipping_company] => Array(
					[label] => Название компании
					[class] => Array(
							[0] => form-row-wide
					)
					[autocomplete] => organization
					[priority] => 30
					[required] => 
			)

			[shipping_country] => Array(
					[type] => country
					[label] => Страна
					[required] => 1
					[class] => Array(
							[0] => form-row-wide
							[1] => address-field
							[2] => update_totals_on_change
					)
					[autocomplete] => country
					[priority] => 40
			)

			[shipping_address_1] => Array(
					[label] => Адрес
					[placeholder] => Номер дома и название улицы
					[required] => 1
					[class] => Array(
							[0] => form-row-wide
							[1] => address-field
					)
					[autocomplete] => address-line1
					[priority] => 50
			)

			[shipping_address_2] => Array(
					[placeholder] => Дополнительные сведения об адресе (необязательно)
					[class] => Array(
							[0] => form-row-wide
							[1] => address-field
					)
					[autocomplete] => address-line2
					[priority] => 60
					[required] => 
			)

			[shipping_city] => Array(
					[label] => Населённый пункт
					[required] => 1
					[class] => Array(
							[0] => form-row-wide
							[1] => address-field
					)
					[autocomplete] => address-level2
					[priority] => 70
			)

			[shipping_state] => Array(
					[type] => state
					[label] => Область / район
					[required] => 1
					[class] => Array(
							[0] => form-row-wide
							[1] => address-field
					)
					[validate] => Array(
							[0] => state
					)
					[autocomplete] => address-level1
					[priority] => 80
					[country_field] => shipping_country
					[country] => RU
			)

			[shipping_postcode] => Array(
					[label] => Почтовый индекс
					[required] => 1
					[class] => Array(
							[0] => form-row-wide
							[1] => address-field
					)
					[validate] => Array(
							[0] => postcode
					)
					[autocomplete] => postal-code
					[priority] => 90
			)

		)

	[account] => Array()

	[order] => Array(
			[order_comments] => Array(
					[type] => textarea
					[class] => Array(
							[0] => notes
					)
					[label] => Примечание к заказу
					[placeholder] => Примечания к вашему заказу, например, особые пожелания отделу доставки.
			)

	)

)

Примеры

#1 Удалим поле "Название компании" из форм на странице "Оформление заказа"

add_filter( 'woocommerce_checkout_fields', 'remove_billing_company_field' );

/**
 * Удаляет из форм на странице "Оформление заказа" поле "Название компании".
 *
 * @param array $fields
 *
 * @return array
 */
function remove_billing_company_field( $fields ){
	unset( $fields['billing']['billing_company'] );
	unset( $fields['shipping']['shipping_company'] );

	return $fields;
}

Где вызывается хук

WC_Checkout::get_checkout_fields()
woocommerce_checkout_fields
woocommerce/includes/class-wc-checkout.php 265
$this->fields = apply_filters( 'woocommerce_checkout_fields', $this->fields );

Где используется хук (в ядре WC)

Использование не найдено.
campusboy 3433youtube.com/c/wpplus
Создатель YouTube канала wp-plus, на котором делюсь своим опытом. Активный пользователь wp-kama.ru. WordPress-разработчик. Разработка сайтов и лендингов. Доработка существующих проектов. Сопровождение ресурсов.
Редакторы: Kama 7641
Комментариев нет
    Здравствуйте, !     Войти . Зарегистрироваться