How to Get The Delivery Information If You Need It

Sometimes you need to fetch the delivery information for some external use like for showing delivery information on a custom order received or thank you page. So how to get the delivery information from an order.

If you need only the metadata name then they are

Order Type: delivery_type
Delivery Date: delivery_date
Delivery Time: delivery_time
Pickup Date: pickup_date
Pickup Time: pickup_time
Pickup Location: delivery_pickup
Special order Notes: additional_note

The following code will help you to get that information. Here $order_id is the id of the order for which you fetch the information

For Delivery Date: 

if(metadata_exists('post', $order_id, 'delivery_date') && get_post_meta($order_id, 'delivery_date', true) !="") {
   $delivery_date = get_post_meta( $order_id, 'delivery_date', true );
}

$delivery_date is the order delivery date

For Delivery Time:

if(metadata_exists('post', $order_id, 'delivery_time') && get_post_meta($order_id,"delivery_time",true) != "") {
   if(get_post_meta($order_id,"delivery_time",true) == "as-soon-as-possible") {
      $delivery_time = As Soon As Possible;
   } else {
      $delivery_time = get_post_meta($order_id,"delivery_time",true);
   }
}

$delivery_time is the order delivery time

For Pickup Date: 

if(metadata_exists('post', $order_id, 'pickup_date') && get_post_meta($order_id, 'pickup_date', true) !="") {
   $pickup_date = get_post_meta( $order_id, 'pickup_date', true );
}

$pickup_date is the order pickup date

For Pickup Time:

if(metadata_exists('post', $order_id, 'pickup_time') && get_post_meta($order_id,"pickup_time",true) != "") {
   $pickup_time = get_post_meta($order_id,"pickup_time",true);
}

$pickup_time is the order pickup time

For Pickup Location:

if(metadata_exists('post', $order_id, 'delivery_pickup') && get_post_meta($order_id,"delivery_pickup",true) != "") {
   $pickup_location = get_post_meta($order_id,"delivery_pickup",true);
}

$pickup_location is the order pickup location

For Additional Note:

if(metadata_exists('post', $order_id, 'additional_note') && get_post_meta($order_id,"additional_note",true) != "") {
   $additional_note = get_post_meta($order_id,"additional_note",true);
}

$additional_note is the order additional note

Still Stuck? How can we help?

Updated on January 14, 2021