How to Get The Delivery Information If You Need It?
Sometimes, you need to fetch the delivery information for external use, like showing it on a custom order received or thank you page. So, how do you 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: pickup_location
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 );
}
if HPOS is activated then
$order = wc_get_order($order_id);
if($order->meta_exists('delivery_date') && $order->get_meta( 'delivery_date', true ) != "") {
$delivery_date = $order->get_meta( '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);
}
}
if HPOS is activated then
$order = wc_get_order($order_id);
if($order->meta_exists('delivery_time') && $order->get_meta( 'delivery_time', true ) != "") {
if($order->get_meta( 'delivery_time', true ) == "as-soon-as-possible") {
$delivery_time = As Soon As Possible;
} else {
$delivery_time = $order->get_meta( '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 );
}
if HPOS is activated then
$order = wc_get_order($order_id);
if($order->meta_exists('pickup_date') && $order->get_meta( 'pickup_date', true ) != "") {
$delivery_date = $order->get_meta( '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);
}
if HPOS is activated then
$order = wc_get_order($order_id);
if($order->meta_exists('pickup_time') && $order->get_meta( 'pickup_time', true ) != "") {
$pickup_time = $order->get_meta( 'pickup_time', true );
}
$pickup_time
is the order pickup time
For Pickup Location:
if(metadata_exists('post', $order_id, 'pickup_location') && get_post_meta($order_id,"pickup_location",true) != "") {
$pickup_location = get_post_meta($order_id,"pickup_location",true);
}
if HPOS is activated then
$order = wc_get_order($order_id);
if($order->meta_exists('pickup_location') && $order->get_meta( 'pickup_location', true ) != "") {
$pickup_location = $order->get_meta( 'pickup_location', 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);
}
if HPOS is activated then
$order = wc_get_order($order_id);
if($order->meta_exists('additional_note') && $order->get_meta( 'additional_note', true )!= "") {
$additional_note = $order->get_meta( 'additional_note', true );
}
$additional_note
is the order additional note
Still Stuck? How can we help?
Updated on December 3, 2024