Skip to content

Instantly share code, notes, and snippets.

@luizbills
Created July 22, 2017 22:26
Show Gist options
  • Save luizbills/12a75217aeff06c716ad5198d17d858c to your computer and use it in GitHub Desktop.
Save luizbills/12a75217aeff06c716ad5198d17d858c to your computer and use it in GitHub Desktop.
Mostrar mais informações nos e-mails do WooCommerce
<?php
/**
* @author Luiz Paulo Bills <[email protected]>
* @version 1.0.0
*/
add_filter( 'woocommerce_email_customer_details_fields', 'lpb_email_with_extra_fields', 10, 3 );
function lpb_email_with_extra_fields ( $fields, $sent_to_admin, $order ) {
$order_id = $order->get_id();
$extra_fields = array(
'Celular' => 'billing_cellphone',
'CPF' => 'billing_cpf',
'RG' => 'billing_rg',
'CNPJ' => 'billing_cnpj',
'Razão Social' => 'billing_company',
'Inscrição Estadual' => 'billing_ie',
'Data de Nascimento' => 'billing_birthdate',
'Sexo' => 'billing_sex',
);
$person_type = intval( get_post_meta( $order_id, '_billing_persontype', true ) );
foreach( $extra_fields as $label => $id ) {
if ( $person_type === 1 ) {
if ( $id === 'billing_cnpj') continue;
if ( $id === 'billing_company' ) continue;
if ( $id === 'billing_ie' ) continue;
} elseif ( $person_type === 2 ) {
if ( $id === 'billing_cpf') continue;
if ( $id === 'billing_rg') continue;
}
$value = get_post_meta( $order_id, '_' . $id, true );
if ( ! empty( $value ) ) {
$fields[] = array(
'label' => $label,
'value' => esc_html( $value )
);
}
}
return $fields;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment