Home Forums Backend Issues (wp-admin) WooCommerce $order woes


WooCommerce $order woes

  • In the code below, I am trying to get the ACF fields of ‘shipping_service’ and ‘tracking_number’ to show up in my order-complete emails to customers, but it only shows up the second time I send emails to my customers. It’s been stressing me out for months and I can’t solve this by myself. Will any of you PLEASE help me?

    add_action( ‘woocommerce_email_after_order_table’, ‘woocommerce_email_after_order_table_func’ );
    function woocommerce_email_after_order_table_func( $order ) {
    $ship = get_field($order->id, ‘shipping_service’, true);
    $track = get_field($order->id, ‘tracking_number’, true);

    $status = $order->get_status();
    $shippingService = get_post_meta($order->id, ‘shipping_service’, true);
    $trackingNumber = get_post_meta($order->id, ‘tracking_number’, true);
    $trackingURL = ”;
    switch ($shippingService) {
    case “FedEx”:
    $trackingURL = “”;
    case “USPS”:
    $trackingURL = “”;


    if($status == “completed”){

    <h3>Shipping Information:</h3>
    <td>Tracking Number: </td>

    <?php echo $trackingNumber; ?>

    <td><?php echo $track; ?></td>

    <td>Shipping Service: </td>
    <td><?php echo $shippingService; ?></td>
    <td><?php echo $ship; ?></td>

    $trackingURL = NULL;
    } else {
    <h3>When we have your order shipped, we will send an email with that information.</h3>

    • James

    • July 14, 2019 at 2:04 am

    Hi @lightsage88

    It’s most likely that you are trying to load the field values before they are actually saved into the database.

    Kindly try changing the priority of the ‘woocommerce_email_after_order_table’ to above 10 to see if you are able to load the field.

    Hope to hear from you soon.

    • rlcesar

    • March 24, 2020 at 4:03 am


    I have exactly the same issue. I tried using priority 1, but the issue is the same. It seems that the mail is beeing sent before updating the ACF field.

    Some new idea?

    Thank you in advance

    • rlcesar

    • March 24, 2020 at 5:09 am

    Hello again,

    I found a solution for this issue without ACF. Using the code that you can find here, the issue is the same, but if you change the priority to the ‘woocommerce_process_shop_order_meta’ add_action to ‘1’, the issue is solved.

    I asked to myself (and to you) if there is any way to solve this issue using ACF.

    Thanks all

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.