2
votes

I added some fields in the WooCommerce orders page using Advanced Custom Fields (ACF) plugin to work as tracking information. Essentially I want the admin to fill out this info and it will be sent in the completed email to the customer once their order has been marked complete.

Does anyone know how I can get the ACF values?

Below is the code inside my customer-completed-order.php file. Obviously it's not working.

$order = new WC_Order($order_id);

//set tracking variables from advanced custom fields plugin
$tracking   = get_field('tracking-code', $order);
$carrier    = get_field('carrier-name', $order);
$date       = get_field('pickup_date', $order);

<p>Your order has been picked up by <?php echo $carrier; ?> on <?php echo $date; ?>. Your tracking code is <?php echo $tracking; ?>.</p>
1

1 Answers

2
votes

Your problem is that you have to use the $order_id instead of the order object this way:

//set tracking variables from advanced custom fields plugin
$tracking   = get_field('tracking-code', $order_id);
$carrier    = get_field('carrier-name', $order_id);
$date       = get_field('pickup_date', $order_id);

?>

<p>Your order has been picked up by <?php echo $carrier; ?> on <?php echo $date; ?>. Your tracking code is <?php echo $tracking; ?>.</p>

This should work, and you not need to get an instance of the $order object in your code.

Reference: <?php $field = get_field($field_name, $post_id, $format_value); ?>