for illustration, i have these fields:
1. the courier used to send an item to customer (slug is courier_o
)
2. the tracking number for no. 1 (slug is tracking_o
)
3. the courier used to send an item (slug is courier_i
)
4. the tracking number for no. 3 (slug is tracking_i
)
what i’m trying to do is update status to “shipping” when fields 1 & 2 has value & update status to “sending back” when fields 3 & 4 has value. to be more specific, these 4 fields exist in one field group & is displayed in the order management page.
regarding changing the order status, i already know how to do it, so i’ll type that as update_order_status($status, $order_id)
.
after going through the forum & docs, i think that for my use, the acf/update_field hook might be useful. problem is, i’m not exactly sure how i should use it with my current code, which looks roughly like this.
<?php
global $woocommerce, $post;
$order = new WC_Order($post->ID);
//to escape # from order id
$order_id = trim(str_replace('#', '', $order->get_order_number()));
$courier_o = get_field('courier_o', $order_id);
$tracking_o = get_field('tracking_o', $order_id);
$courier_i = get_field('courier_i', $order_id);
$tracking_i = get_field('tracking_i', $order_id);
if(!empty($courier_o) && !empty($tracking_o)){
update_order_status('shipping', $order_id);
}
if(!empty($courier_i) && !empty($tracking_i)){
update_order_status('sending-back', $order_id);
}
any reply will be much appreciated. thanks a lot