By csandreas1


2019-01-12 07:11:06 8 Comments

I 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:

enter image description here

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>

2 comments

@csandreas1 2019-01-13 11:59:46

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 
    }
    ?>

@Melissa Freeman 2019-01-13 03:41:38

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>

Related Questions

Sponsored Content

1 Answered Questions

How to echo a PHP code into WooCommerce variation product?

0 Answered Questions

Add a custom variable to Woocommerce Follow-ups plugin

0 Answered Questions

1 Answered Questions

[SOLVED] How to include a custom field in the woocommerce email?

1 Answered Questions

Populate Woocommerce order notes with custom field value

0 Answered Questions

2 Answered Questions

[SOLVED] Woocommerce checkout field maxlength, make input number field only (postcode)

2 Answered Questions

1 Answered Questions

1 Answered Questions

[SOLVED] wordpress shortcode not working

Sponsored Content