get_order_custom_fields($order);
if (empty($custom_fields)) {
return;
}
if ($plain_text) {
// Plain text email format
echo "\n" . esc_html__('Additional Information:', 'akz-checkout-fields-manager-for-woocommerce') . "\n\n";
foreach ($custom_fields as $field) {
echo esc_html($field['label']) . ': ' . esc_html($field['value']) . "\n";
}
echo "\n";
} else {
// HTML email format
?>
get_order_custom_fields($order);
if (empty($custom_fields)) {
return;
}
?>
get_id() : $order->id;
$custom_fields = array();
// Get all custom fields (both Classic and Block)
$classic_fields = $this->get_classic_custom_fields();
$block_fields = $this->get_block_custom_fields();
$all_fields = array_merge($classic_fields, $block_fields);
foreach ($all_fields as $field) {
$field_key = $field['field_key'];
// Get value from order meta
$value = $order->get_meta('_' . $field_key);
// Also try without underscore (some fields might be saved differently)
if (empty($value)) {
$value = $order->get_meta($field_key);
}
// Skip if no value
if (empty($value)) {
continue;
}
// Format value based on field type
$formatted_value = $this->format_field_value($value, $field['field_type'], $field);
$custom_fields[] = array(
'label' => $field['label'],
'value' => $formatted_value,
'key' => $field_key
);
}
return $custom_fields;
}
/**
* Get Classic Checkout custom fields
*/
private function get_classic_custom_fields() {
if (!class_exists('CFEP_Field_Manager')) {
return array();
}
$field_manager = CFEP_Field_Manager::instance();
$all_fields = $field_manager->get_all_fields();
// Filter only enabled custom fields (not WooCommerce defaults)
$custom_fields = array();
foreach ($all_fields as $field) {
// Skip disabled fields
if (!$field['enabled']) {
continue;
}
// Skip default WooCommerce fields (we only want custom fields)
$default_fields = array(
'billing_first_name', 'billing_last_name', 'billing_company',
'billing_address_1', 'billing_address_2', 'billing_city',
'billing_state', 'billing_postcode', 'billing_country',
'billing_email', 'billing_phone',
'shipping_first_name', 'shipping_last_name', 'shipping_company',
'shipping_address_1', 'shipping_address_2', 'shipping_city',
'shipping_state', 'shipping_postcode', 'shipping_country', 'shipping_phone',
'order_comments'
);
if (in_array($field['field_key'], $default_fields)) {
continue;
}
$custom_fields[] = $field;
}
return $custom_fields;
}
/**
* Get Block Checkout custom fields
*/
private function get_block_custom_fields() {
if (!class_exists('CFEP_Block_Field_Manager')) {
return array();
}
$block_manager = CFEP_Block_Field_Manager::instance();
$all_fields = $block_manager->get_all_fields();
// Filter only enabled custom fields
$custom_fields = array();
foreach ($all_fields as $field) {
// Skip disabled fields
if (!$field['enabled']) {
continue;
}
// Skip default WooCommerce fields
if (isset($field['is_default']) && $field['is_default'] == 1) {
continue;
}
$custom_fields[] = $field;
}
return $custom_fields;
}
/**
* Format field value for display
*/
private function format_field_value($value, $field_type, $field) {
switch ($field_type) {
case 'checkbox':
// Checkbox value is usually 1/0 or yes/no
if ($value == 1 || $value == 'yes' || $value == 'on') {
return __('Yes', 'akz-checkout-fields-manager-for-woocommerce');
} else {
return __('No', 'akz-checkout-fields-manager-for-woocommerce');
}
case 'select':
case 'radio':
// Try to get the label from options
if (isset($field['options']) && is_array($field['options'])) {
if (isset($field['options'][$value])) {
return $field['options'][$value];
}
}
return $value;
case 'textarea':
// Convert line breaks to
for HTML display
return nl2br(esc_html($value));
case 'date':
// Format date nicely
if (strtotime($value)) {
return date_i18n(get_option('date_format'), strtotime($value));
}
return $value;
default:
return esc_html($value);
}
}
}
// Initialize
CFEP_Email_Display::instance();