Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 6 years ago.
Improve this questionI am creating a custom field Tracking_ID
on Woocommerce, where the admin will enter the tracking ID as value.
How can i get the value of the created custom field and display it inside the customer-completed-order.php
Also (Optional) i want to show the tracking ID field in the user's track-order
order page in his/her my-account.
Woocommerce>order field:
oceanwp-child/woocommerce/emails/customer-completed-order.php
<?php /* translators: %s: Customer first name */ ?>
<p><?php printf( esc_html__( 'Hi %s,', 'woocommerce' ), esc_html( $order->get_billing_first_name() ) ); ?></p>
<?php /* translators: %s: Site title */ ?>
<p><?php printf( esc_html__( 'Your %s order is completed. Your tracking number is: {$fld}', 'woocommerce' ), esc_html( wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ) ) ); ?></p>
Closed. This question is off-topic. It is not currently accepting answers.
Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 6 years ago.
Improve this questionI am creating a custom field Tracking_ID
on Woocommerce, where the admin will enter the tracking ID as value.
How can i get the value of the created custom field and display it inside the customer-completed-order.php
Also (Optional) i want to show the tracking ID field in the user's track-order
order page in his/her my-account.
Woocommerce>order field:
oceanwp-child/woocommerce/emails/customer-completed-order.php
<?php /* translators: %s: Customer first name */ ?>
<p><?php printf( esc_html__( 'Hi %s,', 'woocommerce' ), esc_html( $order->get_billing_first_name() ) ); ?></p>
<?php /* translators: %s: Site title */ ?>
<p><?php printf( esc_html__( 'Your %s order is completed. Your tracking number is: {$fld}', 'woocommerce' ), esc_html( wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ) ) ); ?></p>
The syntax to get your custom field is:
get_post_meta($post_id, $key, $single);
In your context, you should try:
$tracking_id = get_post_meta($order->get_order_number(), 'Tracking_ID', true);
To show you in your example:
<?php /* translators: %s: Site title */
$tracking_id = get_post_meta($order->get_order_number(), 'Tracking_ID', true); ?>
<p><?php printf( esc_html__( 'Your %s order is completed. Your tracking number is: %s', 'woocommerce' ), esc_html( wp_specialchars_decode( get_option( 'blogname' ), esc_html($tracking_id) ) ) ); ?></p>
Based on Melissa's answer, here is what i did and it worked for me.
<?php
#Tracking ID
$tracking_id = get_post_meta($order->get_order_number(), 'Tracking_ID', true);
if( ! empty($tracking_id) )
{ ?>
<p> <?php
printf( esc_html__( 'Your tracking number is: %s', 'woocommerce' ), esc_html($tracking_id) );?>
</p> <?php
}
?>