"Billing user name", ); public $display_name = 'Order custom field ...'; public function getValue($post, $field) { $field = $field['value']; $order = $this->getOrder($post); if (empty($order)) { return ''; } $orderPost = get_post($order->get_id()); if ('billing_user_name' === $field) { $result = $order->get_formatted_billing_full_name(); } elseif ('shipping_user_name' === $field) { $result = $order->get_formatted_shipping_full_name(); } elseif (in_array($field, array('_order_subtotal'))) { $result = $this->getOrderSubtotal($orderPost); } elseif (class_exists('\Automattic\WooCommerce\Utilities\OrderUtil')) { $result = \Automattic\WooCommerce\Utilities\OrderUtil::get_post_or_object_meta($post, $order, $field, true); if ($this->shouldAddCurrency(array('value' => $field))) { $result = $this->getValueWithCurrency($result); } } elseif (in_array($field, get_post_custom_keys($orderPost->ID) ?: array())) { $result = get_post_meta($orderPost->ID, $field, true); if ($this->shouldAddCurrency(array('value' => $field))) { $result = $this->getValueWithCurrency($result); } } else { $result = ''; } return $result; } protected function getCountryFullName($countryCode) { $countries = apply_filters('woocommerce_countries', include WC()->plugin_path() . '/i18n/countries.php'); $countryFullName = (is_array($countries) && isset($countries[$countryCode])) ? $countries[$countryCode] : $countryCode; return preg_replace("/\s\(.*\)/", '', $countryFullName); } protected function getStateFullName($countryCode, $stateCode) { $states = apply_filters('woocommerce_countries', include WC()->plugin_path() . '/i18n/states.php'); return (is_array($states) && isset($states[$countryCode][$stateCode])) ? $states[$countryCode][$stateCode] : $stateCode; } protected function getOrderSubtotal($post) { $orderTotal = $this->getProductMeta($post, "_order_total", true); $orderTax = $this->getProductMeta($post, "_order_tax", true); $orderSubtotal = $orderTax ? $orderTotal - $orderTax : $orderTotal; return $this->getValueWithCurrency($orderSubtotal); } public function getName($field) { $fieldName = isset($this->fieldNames[$field['value']]) ? $this->fieldNames[$field['value']] : ''; } }