Automattic\WooCommerce\Admin\API\Reports\Orders
DataStore::get_order_attributions_by_order_ids()
Get order attributions data from order IDs.
Method of the class: DataStore{}
No Hooks.
Return
Array
.
Usage
// protected - for code of main (parent) or child class $result = $this->get_order_attributions_by_order_ids( $order_ids );
- $order_ids(array) (required)
- Array of order IDs.
DataStore::get_order_attributions_by_order_ids() DataStore::get order attributions by order ids code WC 9.3.3
protected function get_order_attributions_by_order_ids( $order_ids ) { global $wpdb; $order_meta_table = OrdersTableDataStore::get_meta_table_name(); $included_order_ids = implode( ',', array_map( 'absint', $order_ids ) ); if ( OrderUtil::custom_orders_table_usage_is_enabled() ) { /* phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared */ $order_attributions_meta = $wpdb->get_results( "SELECT order_id, meta_key, meta_value FROM $order_meta_table WHERE order_id IN ({$included_order_ids}) AND meta_key IN ( '_wc_order_attribution_source_type', '_wc_order_attribution_utm_source' ) ", ARRAY_A ); /* phpcs:enable */ } else { /* phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared */ $order_attributions_meta = $wpdb->get_results( "SELECT post_id as order_id, meta_key, meta_value FROM $wpdb->postmeta WHERE post_id IN ({$included_order_ids}) AND meta_key IN ( '_wc_order_attribution_source_type', '_wc_order_attribution_utm_source' ) ", ARRAY_A ); /* phpcs:enable */ } $order_attributions = array(); foreach ( $order_attributions_meta as $meta ) { if ( ! isset( $order_attributions[ $meta['order_id'] ] ) ) { $order_attributions[ $meta['order_id'] ] = array(); } $order_attributions[ $meta['order_id'] ][ $meta['meta_key'] ] = $meta['meta_value']; } return $order_attributions; }