Home › Forums › Backend Issues (wp-admin) › 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 = “http://www.fedex.com/Tracking?tracknumbers=”;
break;
case “USPS”:
$trackingURL = “https://tools.usps.com/go/TrackConfirmAction?tLabels=”;
break;
}
if($status == “completed”){
?>
<h3>Shipping Information:</h3>
<table>
<tr>
<td>Tracking Number: </td>
<td>
“>
<?php echo $trackingNumber; ?>
</td>
<td><?php echo $track; ?></td>
</tr>
<tr>
<td>Shipping Service: </td>
<td><?php echo $shippingService; ?></td>
<td><?php echo $ship; ?></td>
</tr>
</table>
<?php
$trackingURL = NULL;
} else {
?>
<h3>When we have your order shipped, we will send an email with that information.</h3>
<?php
}
}
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.
Hello,
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
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
Did anyone manage to find a solution to this using ACF?
I have tried to change the priority of the order completed email from Woocommerce but it still fires before the ACF field updates.
Here is what I tried:
add_action( 'woocommerce_email', 'unhook_those_pesky_emails' );
function unhook_those_pesky_emails( $email_class ) {
remove_action( 'woocommerce_order_status_completed_notification', array( $email_class->emails['WC_Email_Customer_Completed_Order'], 'trigger' ) );
add_action( 'woocommerce_order_status_completed_notification', array( $email_class->emails['WC_Email_Customer_Completed_Order'], 'trigger' ), 90, 2 );
}
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
🤔 Curious about the ACF user experience? So are we! Help guide the evolution of ACF by taking part in our first ever Annual Survey and guarantee you’re represented in the results. https://t.co/0cgr9ZFOJ5
— Advanced Custom Fields (@wp_acf) May 8, 2023
© 2023 Advanced Custom Fields.
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.