Abstract_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: Abstract_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. |
Abstract_WC_Order_Data_Store_CPT::read_order_data() Abstract WC Order Data Store CPT::read order data code WC 10.3.3
protected function read_order_data( &$order, $post_object ) {
$id = $order->get_id();
$meta_data = get_post_meta( $id );
$prices_include_tax = $meta_data['_prices_include_tax'][0] ?? '';
$this->set_order_props(
$order,
array(
'currency' => $meta_data['_order_currency'][0] ?? '',
'discount_total' => $meta_data['_cart_discount'][0] ?? '',
'discount_tax' => $meta_data['_cart_discount_tax'][0] ?? '',
'shipping_total' => $meta_data['_order_shipping'][0] ?? '',
'shipping_tax' => $meta_data['_order_shipping_tax'][0] ?? '',
'cart_tax' => $meta_data['_order_tax'][0] ?? '',
'total' => $meta_data['_order_total'][0] ?? '',
'version' => $meta_data['_order_version'][0] ?? '',
'prices_include_tax' => metadata_exists( 'post', $id, '_prices_include_tax' ) ? 'yes' === $prices_include_tax : 'yes' === get_option( 'woocommerce_prices_include_tax' ),
)
);
// Gets extra data associated with the order if needed.
foreach ( $order->get_extra_data_keys() as $key ) {
$function = 'set_' . $key;
if ( is_callable( array( $order, $function ) ) ) {
$order->{$function}( $meta_data[ '_' . $key ][0] ?? '' );
}
}
}