WC_Order_Data_Store_CPT::read_order_data
Read order data. Can be overridden by child classes to load other props.
Method of the class: WC_Order_Data_Store_CPT{}
No Hooks.
Returns
null. Nothing (null).
Usage
// protected - for code of main (parent) or child class $result = $this->read_order_data( $order, $post_object );
- $order(WC_Order) (required) (passed by reference — &)
- Order object.
- $post_object(object) (required)
- Post object.
Changelog
| Since 3.0.0 | Introduced. |
WC_Order_Data_Store_CPT::read_order_data() WC Order Data Store CPT::read order data code WC 10.6.2
protected function read_order_data( &$order, $post_object ) {
parent::read_order_data( $order, $post_object );
$id = $order->get_id();
$post_meta = get_post_meta( $id );
$date_completed = $post_meta['_date_completed'][0] ?? '';
$date_paid = $post_meta['_date_paid'][0] ?? '';
if ( ! $date_completed ) {
$date_completed = $post_meta['_completed_date'][0] ?? '';
}
if ( ! $date_paid ) {
$date_paid = $post_meta['_paid_date'][0] ?? '';
}
$order->set_props(
array(
'order_key' => $post_meta['_order_key'][0] ?? '',
'customer_id' => $post_meta['_customer_user'][0] ?? '',
'billing_first_name' => $post_meta['_billing_first_name'][0] ?? '',
'billing_last_name' => $post_meta['_billing_last_name'][0] ?? '',
'billing_company' => $post_meta['_billing_company'][0] ?? '',
'billing_address_1' => $post_meta['_billing_address_1'][0] ?? '',
'billing_address_2' => $post_meta['_billing_address_2'][0] ?? '',
'billing_city' => $post_meta['_billing_city'][0] ?? '',
'billing_state' => $post_meta['_billing_state'][0] ?? '',
'billing_postcode' => $post_meta['_billing_postcode'][0] ?? '',
'billing_country' => $post_meta['_billing_country'][0] ?? '',
'billing_email' => $post_meta['_billing_email'][0] ?? '',
'billing_phone' => $post_meta['_billing_phone'][0] ?? '',
'shipping_first_name' => $post_meta['_shipping_first_name'][0] ?? '',
'shipping_last_name' => $post_meta['_shipping_last_name'][0] ?? '',
'shipping_company' => $post_meta['_shipping_company'][0] ?? '',
'shipping_address_1' => $post_meta['_shipping_address_1'][0] ?? '',
'shipping_address_2' => $post_meta['_shipping_address_2'][0] ?? '',
'shipping_city' => $post_meta['_shipping_city'][0] ?? '',
'shipping_state' => $post_meta['_shipping_state'][0] ?? '',
'shipping_postcode' => $post_meta['_shipping_postcode'][0] ?? '',
'shipping_country' => $post_meta['_shipping_country'][0] ?? '',
'shipping_phone' => $post_meta['_shipping_phone'][0] ?? '',
'payment_method' => $post_meta['_payment_method'][0] ?? '',
'payment_method_title' => $post_meta['_payment_method_title'][0] ?? '',
'transaction_id' => $post_meta['_transaction_id'][0] ?? '',
'customer_ip_address' => $post_meta['_customer_ip_address'][0] ?? '',
'customer_user_agent' => $post_meta['_customer_user_agent'][0] ?? '',
'created_via' => $post_meta['_created_via'][0] ?? '',
'date_completed' => $date_completed,
'date_paid' => $date_paid,
'cart_hash' => $post_meta['_cart_hash'][0] ?? '',
'customer_note' => $post_object->post_excerpt,
// Operational data props.
'order_stock_reduced' => $post_meta['_order_stock_reduced'][0] ?? '',
'download_permissions_granted' => $post_meta['_download_permissions_granted'][0] ?? '',
'new_order_email_sent' => $post_meta['_new_order_email_sent'][0] ?? '',
'recorded_sales' => wc_string_to_bool( $post_meta['_recorded_sales'][0] ?? '' ),
'recorded_coupon_usage_counts' => $post_meta['_recorded_coupon_usage_counts'][0] ?? '',
)
);
if ( $this->cogs_is_enabled() && $order->has_cogs() ) {
$this->read_cogs_data( $order, $post_meta );
}
}