Skip to content

Instantly share code, notes, and snippets.

@crmplease

crmplease/hook.php

Last active Jul 29, 2019
Embed
What would you like to do?
Отчество в WooCommerce
<?php
/**
* Отчетсво в метабоксе информации о заказе
*/
add_filter('woocommerce_admin_billing_fields', function ($fields) {
$names = array(
'last_name' => array(
'label' => __('Фамилия'),
'show' => false,
),
'first_name' => array(
'label' => __('Имя'),
'show' => false,
),
'middle_name' => array(
'label' => __('Отчество'),
'show' => false,
),
);
unset($fields['first_name']);
unset($fields['last_name']);
return $names + $fields;
}, 10, 1);
/**
* Отчетсво в функции форматирования адреса get_formatted_billing_address
*/
add_filter('woocommerce_order_formatted_billing_address', function ($address, $order) {
$address['middle_name'] = $order->get_meta('_billing_middle_name');
return $address;
}, 10, 2);
/**
* Отчетсво в функции форматирования адреса get_formatted_shipping_address
*/
add_filter('woocommerce_order_formatted_shipping_address', function ($address, $order) {
$address['middle_name'] = $order->get_meta('_billing_middle_name');
return $address;
}, 10, 2);
/**
* Отчетсво в функции форматирования адреса get_formatted_address
*/
add_filter('woocommerce_formatted_address_replacements', function ($replacements, $args) {
if (isset($args['middle_name'])) {
$replacements['{name}'] = $args['last_name'] . ' ' . $args['first_name'] . ' ' . $args['middle_name'];
} else {
$replacements['{name}'] = $args['last_name'] . ' ' . $args['first_name'];
}
return $replacements;
}, 10, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment