Add Custom fields values to Woocommerce email notification
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 |
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 |
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 '18 at 1:51
LoicTheAztec
86.2k136398
86.2k136398
asked Nov 22 '18 at 15:00
Claudio MartinezClaudio Martinez
337
337
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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 |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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 |
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 |
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 '18 at 1:48
answered Nov 23 '18 at 1:43
LoicTheAztecLoicTheAztec
86.2k136398
86.2k136398
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.
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