Add Custom fields values to Woocommerce email notification
up vote
1
down vote
favorite
I have added to custom fields on the checkout page using YITH checkout Manager billing_customfield1 and billing_customfield2.
I need to show this fields on the email sent by woocommerce.
this is the way , the fields from checkout are being displayed on the email template:
<?php if ( $order->get_billing_first_name() ) : ?>
<br/><?php echo '<b>Nombre: </b>'.esc_html( $order->get_billing_first_name().' '.$order->get_billing_last_name() ); ?>
<?php endif; ?>
<?php if ( $order->get_billing_phone() ) : ?>
<br/><?php echo '<b>Teléfono: </b>'.esc_html( $order->get_billing_phone() ); ?>
<?php endif; ?>
<?php if ( $order->get_billing_company() ) : ?>
<br/><?php echo '<b>Nombre de la empresa: </b>'.esc_html( $order->get_billing_company() ); ?>
<?php endif; ?>
<?php if ( $order->get_billing_address_1() ) : ?>
<br/><?php echo '<b>Dirección: </b>'.esc_html( $order->get_billing_address_1() ); ?>
<?php endif; ?>
<?php if ( $order->get_billing_address_2() ) : ?>
<br/><?php echo '<b>Dirección 2: </b>'.esc_html( $order->get_billing_address_2() ); ?>
<?php endif; ?>
<?php if ( $order->get_billing_city() ) : ?>
<br/><?php echo '<b>Ciudad: </b>'.esc_html( $order->get_billing_city() ); ?>
<?php endif; ?>
I need to show the new 2 custom fields as well but there's no method for
$order->get_customfield1()
php wordpress woocommerce custom-fields orders
add a comment |
up vote
1
down vote
favorite
I have added to custom fields on the checkout page using YITH checkout Manager billing_customfield1 and billing_customfield2.
I need to show this fields on the email sent by woocommerce.
this is the way , the fields from checkout are being displayed on the email template:
<?php if ( $order->get_billing_first_name() ) : ?>
<br/><?php echo '<b>Nombre: </b>'.esc_html( $order->get_billing_first_name().' '.$order->get_billing_last_name() ); ?>
<?php endif; ?>
<?php if ( $order->get_billing_phone() ) : ?>
<br/><?php echo '<b>Teléfono: </b>'.esc_html( $order->get_billing_phone() ); ?>
<?php endif; ?>
<?php if ( $order->get_billing_company() ) : ?>
<br/><?php echo '<b>Nombre de la empresa: </b>'.esc_html( $order->get_billing_company() ); ?>
<?php endif; ?>
<?php if ( $order->get_billing_address_1() ) : ?>
<br/><?php echo '<b>Dirección: </b>'.esc_html( $order->get_billing_address_1() ); ?>
<?php endif; ?>
<?php if ( $order->get_billing_address_2() ) : ?>
<br/><?php echo '<b>Dirección 2: </b>'.esc_html( $order->get_billing_address_2() ); ?>
<?php endif; ?>
<?php if ( $order->get_billing_city() ) : ?>
<br/><?php echo '<b>Ciudad: </b>'.esc_html( $order->get_billing_city() ); ?>
<?php endif; ?>
I need to show the new 2 custom fields as well but there's no method for
$order->get_customfield1()
php wordpress woocommerce custom-fields orders
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have added to custom fields on the checkout page using YITH checkout Manager billing_customfield1 and billing_customfield2.
I need to show this fields on the email sent by woocommerce.
this is the way , the fields from checkout are being displayed on the email template:
<?php if ( $order->get_billing_first_name() ) : ?>
<br/><?php echo '<b>Nombre: </b>'.esc_html( $order->get_billing_first_name().' '.$order->get_billing_last_name() ); ?>
<?php endif; ?>
<?php if ( $order->get_billing_phone() ) : ?>
<br/><?php echo '<b>Teléfono: </b>'.esc_html( $order->get_billing_phone() ); ?>
<?php endif; ?>
<?php if ( $order->get_billing_company() ) : ?>
<br/><?php echo '<b>Nombre de la empresa: </b>'.esc_html( $order->get_billing_company() ); ?>
<?php endif; ?>
<?php if ( $order->get_billing_address_1() ) : ?>
<br/><?php echo '<b>Dirección: </b>'.esc_html( $order->get_billing_address_1() ); ?>
<?php endif; ?>
<?php if ( $order->get_billing_address_2() ) : ?>
<br/><?php echo '<b>Dirección 2: </b>'.esc_html( $order->get_billing_address_2() ); ?>
<?php endif; ?>
<?php if ( $order->get_billing_city() ) : ?>
<br/><?php echo '<b>Ciudad: </b>'.esc_html( $order->get_billing_city() ); ?>
<?php endif; ?>
I need to show the new 2 custom fields as well but there's no method for
$order->get_customfield1()
php wordpress woocommerce custom-fields orders
I have added to custom fields on the checkout page using YITH checkout Manager billing_customfield1 and billing_customfield2.
I need to show this fields on the email sent by woocommerce.
this is the way , the fields from checkout are being displayed on the email template:
<?php if ( $order->get_billing_first_name() ) : ?>
<br/><?php echo '<b>Nombre: </b>'.esc_html( $order->get_billing_first_name().' '.$order->get_billing_last_name() ); ?>
<?php endif; ?>
<?php if ( $order->get_billing_phone() ) : ?>
<br/><?php echo '<b>Teléfono: </b>'.esc_html( $order->get_billing_phone() ); ?>
<?php endif; ?>
<?php if ( $order->get_billing_company() ) : ?>
<br/><?php echo '<b>Nombre de la empresa: </b>'.esc_html( $order->get_billing_company() ); ?>
<?php endif; ?>
<?php if ( $order->get_billing_address_1() ) : ?>
<br/><?php echo '<b>Dirección: </b>'.esc_html( $order->get_billing_address_1() ); ?>
<?php endif; ?>
<?php if ( $order->get_billing_address_2() ) : ?>
<br/><?php echo '<b>Dirección 2: </b>'.esc_html( $order->get_billing_address_2() ); ?>
<?php endif; ?>
<?php if ( $order->get_billing_city() ) : ?>
<br/><?php echo '<b>Ciudad: </b>'.esc_html( $order->get_billing_city() ); ?>
<?php endif; ?>
I need to show the new 2 custom fields as well but there's no method for
$order->get_customfield1()
php wordpress woocommerce custom-fields orders
php wordpress woocommerce custom-fields orders
edited Nov 23 at 1:51
LoicTheAztec
82.7k125993
82.7k125993
asked Nov 22 at 15:00
Claudio Martinez
337
337
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
Since Woocommerce 3, there is a method inherited from WC_Data
Class which is get_meta() and that has to be used on the WC_Order
$order
instance object.
Most of the time, Order custom fields are registered in database with a meta key starting with an underscore in
wp_postmeta
table.
So I will use:_billing_customfield1
and_billing_customfield2
Here is your revisited code:
<?php
if ( $order->get_formatted_billing_full_name() ) {
echo '<br/><b>'.__("Nombre", "woocommerce") . ': </b>' . esc_html( $order->get_formatted_billing_full_name() );
}
if ( $order->get_billing_phone() ) {
echo '<br/><b>'.__("Teléfono", "woocommerce") . ': </b>' . esc_html( $order->get_billing_phone() );
}
if ( $order->get_billing_company() ) {
echo '<br/><b>'.__("Nombre de la empresa", "woocommerce") . ': </b>' . esc_html( $order->get_billing_company() );
}
if ( $order->get_billing_address_1() ) {
echo '<br/><b>'.__("Dirección", "woocommerce") . ': </b>' . esc_html( $order->get_billing_address_1() );
}
if ( $order->get_billing_address_2() ) {
echo '<br/><b>'.__("Dirección 2", "woocommerce") . ': </b>' . esc_html( $order->get_billing_address_2() );
}
if ( $order->get_billing_city() ) {
echo '<br/><b>'.__("Ciudad", "woocommerce") . ': </b>' . esc_html( $order->get_billing_city() );
}
if ( $order->get_meta('_billing_customfield1') ) {
echo '<br/><b>'.__("Campo personalizado 1", "woocommerce") . ': </b>' . esc_html( $order->get_meta('_billing_customfield1') );
}
if ( $order->get_meta('_billing_customfield2') ) {
echo '<br/><b>'.__("Campo personalizado 2", "woocommerce") . ': </b>' . esc_html( $order->get_meta('_billing_customfield2') );
}
?>
It should works if those custom fields slugs are _billing_customfield1
and _billing_customfield2
You should need to verify in your database under wp_postmeta
table that the correct meta_key
are _billing_customfield1
and _billing_customfield2
…
If not you will replace them with the right ones.
You can also use the WordPress get_post_meta()
function that needs the Order ID that you can have with $order->get_id()
like:
if ( get_post_meta( $order->get_id(), '_billing_customfield1', true ) ) {
echo '<br/><b>'.__("Campo personalizado 1", "woocommerce") . ': </b>' . esc_html( get_post_meta( $order->get_id(), '_billing_customfield1', true ) );
}
if ( get_post_meta( $order->get_id(), '_billing_customfield2', true ) ) {
echo '<br/><b>'.__("Campo personalizado 2", "woocommerce") . ': </b>' . esc_html( get_post_meta( $order->get_id(), '_billing_customfield2', true ) );
}
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
Since Woocommerce 3, there is a method inherited from WC_Data
Class which is get_meta() and that has to be used on the WC_Order
$order
instance object.
Most of the time, Order custom fields are registered in database with a meta key starting with an underscore in
wp_postmeta
table.
So I will use:_billing_customfield1
and_billing_customfield2
Here is your revisited code:
<?php
if ( $order->get_formatted_billing_full_name() ) {
echo '<br/><b>'.__("Nombre", "woocommerce") . ': </b>' . esc_html( $order->get_formatted_billing_full_name() );
}
if ( $order->get_billing_phone() ) {
echo '<br/><b>'.__("Teléfono", "woocommerce") . ': </b>' . esc_html( $order->get_billing_phone() );
}
if ( $order->get_billing_company() ) {
echo '<br/><b>'.__("Nombre de la empresa", "woocommerce") . ': </b>' . esc_html( $order->get_billing_company() );
}
if ( $order->get_billing_address_1() ) {
echo '<br/><b>'.__("Dirección", "woocommerce") . ': </b>' . esc_html( $order->get_billing_address_1() );
}
if ( $order->get_billing_address_2() ) {
echo '<br/><b>'.__("Dirección 2", "woocommerce") . ': </b>' . esc_html( $order->get_billing_address_2() );
}
if ( $order->get_billing_city() ) {
echo '<br/><b>'.__("Ciudad", "woocommerce") . ': </b>' . esc_html( $order->get_billing_city() );
}
if ( $order->get_meta('_billing_customfield1') ) {
echo '<br/><b>'.__("Campo personalizado 1", "woocommerce") . ': </b>' . esc_html( $order->get_meta('_billing_customfield1') );
}
if ( $order->get_meta('_billing_customfield2') ) {
echo '<br/><b>'.__("Campo personalizado 2", "woocommerce") . ': </b>' . esc_html( $order->get_meta('_billing_customfield2') );
}
?>
It should works if those custom fields slugs are _billing_customfield1
and _billing_customfield2
You should need to verify in your database under wp_postmeta
table that the correct meta_key
are _billing_customfield1
and _billing_customfield2
…
If not you will replace them with the right ones.
You can also use the WordPress get_post_meta()
function that needs the Order ID that you can have with $order->get_id()
like:
if ( get_post_meta( $order->get_id(), '_billing_customfield1', true ) ) {
echo '<br/><b>'.__("Campo personalizado 1", "woocommerce") . ': </b>' . esc_html( get_post_meta( $order->get_id(), '_billing_customfield1', true ) );
}
if ( get_post_meta( $order->get_id(), '_billing_customfield2', true ) ) {
echo '<br/><b>'.__("Campo personalizado 2", "woocommerce") . ': </b>' . esc_html( get_post_meta( $order->get_id(), '_billing_customfield2', true ) );
}
add a comment |
up vote
1
down vote
Since Woocommerce 3, there is a method inherited from WC_Data
Class which is get_meta() and that has to be used on the WC_Order
$order
instance object.
Most of the time, Order custom fields are registered in database with a meta key starting with an underscore in
wp_postmeta
table.
So I will use:_billing_customfield1
and_billing_customfield2
Here is your revisited code:
<?php
if ( $order->get_formatted_billing_full_name() ) {
echo '<br/><b>'.__("Nombre", "woocommerce") . ': </b>' . esc_html( $order->get_formatted_billing_full_name() );
}
if ( $order->get_billing_phone() ) {
echo '<br/><b>'.__("Teléfono", "woocommerce") . ': </b>' . esc_html( $order->get_billing_phone() );
}
if ( $order->get_billing_company() ) {
echo '<br/><b>'.__("Nombre de la empresa", "woocommerce") . ': </b>' . esc_html( $order->get_billing_company() );
}
if ( $order->get_billing_address_1() ) {
echo '<br/><b>'.__("Dirección", "woocommerce") . ': </b>' . esc_html( $order->get_billing_address_1() );
}
if ( $order->get_billing_address_2() ) {
echo '<br/><b>'.__("Dirección 2", "woocommerce") . ': </b>' . esc_html( $order->get_billing_address_2() );
}
if ( $order->get_billing_city() ) {
echo '<br/><b>'.__("Ciudad", "woocommerce") . ': </b>' . esc_html( $order->get_billing_city() );
}
if ( $order->get_meta('_billing_customfield1') ) {
echo '<br/><b>'.__("Campo personalizado 1", "woocommerce") . ': </b>' . esc_html( $order->get_meta('_billing_customfield1') );
}
if ( $order->get_meta('_billing_customfield2') ) {
echo '<br/><b>'.__("Campo personalizado 2", "woocommerce") . ': </b>' . esc_html( $order->get_meta('_billing_customfield2') );
}
?>
It should works if those custom fields slugs are _billing_customfield1
and _billing_customfield2
You should need to verify in your database under wp_postmeta
table that the correct meta_key
are _billing_customfield1
and _billing_customfield2
…
If not you will replace them with the right ones.
You can also use the WordPress get_post_meta()
function that needs the Order ID that you can have with $order->get_id()
like:
if ( get_post_meta( $order->get_id(), '_billing_customfield1', true ) ) {
echo '<br/><b>'.__("Campo personalizado 1", "woocommerce") . ': </b>' . esc_html( get_post_meta( $order->get_id(), '_billing_customfield1', true ) );
}
if ( get_post_meta( $order->get_id(), '_billing_customfield2', true ) ) {
echo '<br/><b>'.__("Campo personalizado 2", "woocommerce") . ': </b>' . esc_html( get_post_meta( $order->get_id(), '_billing_customfield2', true ) );
}
add a comment |
up vote
1
down vote
up vote
1
down vote
Since Woocommerce 3, there is a method inherited from WC_Data
Class which is get_meta() and that has to be used on the WC_Order
$order
instance object.
Most of the time, Order custom fields are registered in database with a meta key starting with an underscore in
wp_postmeta
table.
So I will use:_billing_customfield1
and_billing_customfield2
Here is your revisited code:
<?php
if ( $order->get_formatted_billing_full_name() ) {
echo '<br/><b>'.__("Nombre", "woocommerce") . ': </b>' . esc_html( $order->get_formatted_billing_full_name() );
}
if ( $order->get_billing_phone() ) {
echo '<br/><b>'.__("Teléfono", "woocommerce") . ': </b>' . esc_html( $order->get_billing_phone() );
}
if ( $order->get_billing_company() ) {
echo '<br/><b>'.__("Nombre de la empresa", "woocommerce") . ': </b>' . esc_html( $order->get_billing_company() );
}
if ( $order->get_billing_address_1() ) {
echo '<br/><b>'.__("Dirección", "woocommerce") . ': </b>' . esc_html( $order->get_billing_address_1() );
}
if ( $order->get_billing_address_2() ) {
echo '<br/><b>'.__("Dirección 2", "woocommerce") . ': </b>' . esc_html( $order->get_billing_address_2() );
}
if ( $order->get_billing_city() ) {
echo '<br/><b>'.__("Ciudad", "woocommerce") . ': </b>' . esc_html( $order->get_billing_city() );
}
if ( $order->get_meta('_billing_customfield1') ) {
echo '<br/><b>'.__("Campo personalizado 1", "woocommerce") . ': </b>' . esc_html( $order->get_meta('_billing_customfield1') );
}
if ( $order->get_meta('_billing_customfield2') ) {
echo '<br/><b>'.__("Campo personalizado 2", "woocommerce") . ': </b>' . esc_html( $order->get_meta('_billing_customfield2') );
}
?>
It should works if those custom fields slugs are _billing_customfield1
and _billing_customfield2
You should need to verify in your database under wp_postmeta
table that the correct meta_key
are _billing_customfield1
and _billing_customfield2
…
If not you will replace them with the right ones.
You can also use the WordPress get_post_meta()
function that needs the Order ID that you can have with $order->get_id()
like:
if ( get_post_meta( $order->get_id(), '_billing_customfield1', true ) ) {
echo '<br/><b>'.__("Campo personalizado 1", "woocommerce") . ': </b>' . esc_html( get_post_meta( $order->get_id(), '_billing_customfield1', true ) );
}
if ( get_post_meta( $order->get_id(), '_billing_customfield2', true ) ) {
echo '<br/><b>'.__("Campo personalizado 2", "woocommerce") . ': </b>' . esc_html( get_post_meta( $order->get_id(), '_billing_customfield2', true ) );
}
Since Woocommerce 3, there is a method inherited from WC_Data
Class which is get_meta() and that has to be used on the WC_Order
$order
instance object.
Most of the time, Order custom fields are registered in database with a meta key starting with an underscore in
wp_postmeta
table.
So I will use:_billing_customfield1
and_billing_customfield2
Here is your revisited code:
<?php
if ( $order->get_formatted_billing_full_name() ) {
echo '<br/><b>'.__("Nombre", "woocommerce") . ': </b>' . esc_html( $order->get_formatted_billing_full_name() );
}
if ( $order->get_billing_phone() ) {
echo '<br/><b>'.__("Teléfono", "woocommerce") . ': </b>' . esc_html( $order->get_billing_phone() );
}
if ( $order->get_billing_company() ) {
echo '<br/><b>'.__("Nombre de la empresa", "woocommerce") . ': </b>' . esc_html( $order->get_billing_company() );
}
if ( $order->get_billing_address_1() ) {
echo '<br/><b>'.__("Dirección", "woocommerce") . ': </b>' . esc_html( $order->get_billing_address_1() );
}
if ( $order->get_billing_address_2() ) {
echo '<br/><b>'.__("Dirección 2", "woocommerce") . ': </b>' . esc_html( $order->get_billing_address_2() );
}
if ( $order->get_billing_city() ) {
echo '<br/><b>'.__("Ciudad", "woocommerce") . ': </b>' . esc_html( $order->get_billing_city() );
}
if ( $order->get_meta('_billing_customfield1') ) {
echo '<br/><b>'.__("Campo personalizado 1", "woocommerce") . ': </b>' . esc_html( $order->get_meta('_billing_customfield1') );
}
if ( $order->get_meta('_billing_customfield2') ) {
echo '<br/><b>'.__("Campo personalizado 2", "woocommerce") . ': </b>' . esc_html( $order->get_meta('_billing_customfield2') );
}
?>
It should works if those custom fields slugs are _billing_customfield1
and _billing_customfield2
You should need to verify in your database under wp_postmeta
table that the correct meta_key
are _billing_customfield1
and _billing_customfield2
…
If not you will replace them with the right ones.
You can also use the WordPress get_post_meta()
function that needs the Order ID that you can have with $order->get_id()
like:
if ( get_post_meta( $order->get_id(), '_billing_customfield1', true ) ) {
echo '<br/><b>'.__("Campo personalizado 1", "woocommerce") . ': </b>' . esc_html( get_post_meta( $order->get_id(), '_billing_customfield1', true ) );
}
if ( get_post_meta( $order->get_id(), '_billing_customfield2', true ) ) {
echo '<br/><b>'.__("Campo personalizado 2", "woocommerce") . ': </b>' . esc_html( get_post_meta( $order->get_id(), '_billing_customfield2', true ) );
}
edited Nov 23 at 1:48
answered Nov 23 at 1:43
LoicTheAztec
82.7k125993
82.7k125993
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53433640%2fadd-custom-fields-values-to-woocommerce-email-notification%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown