php - tracking number field in Woocommerce order

admin2025-06-04  4

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 question

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:

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 question

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:

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>
Share Improve this question edited Jan 13, 2019 at 11:03 csandreas1 asked Jan 12, 2019 at 7:11 csandreas1csandreas1 2063 silver badges11 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 1

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 
    }
    ?>
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749016466a315645.html

最新回复(0)