Automattic\WooCommerce\Admin\API\Reports\Orders
DataStore::get_coupons_by_order_ids()
Get coupon information 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_coupons_by_order_ids( $order_ids );
- $order_ids(array) (required)
- Array of order IDs.
DataStore::get_coupons_by_order_ids() DataStore::get coupons by order ids code WC 8.7.0
protected function get_coupons_by_order_ids( $order_ids ) { global $wpdb; $order_coupon_lookup_table = $wpdb->prefix . 'wc_order_coupon_lookup'; $included_order_ids = implode( ',', $order_ids ); /* phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared */ $coupons = $wpdb->get_results( "SELECT order_id, coupon_id, post_title as coupon_code FROM {$wpdb->posts} JOIN {$order_coupon_lookup_table} ON {$order_coupon_lookup_table}.coupon_id = {$wpdb->posts}.ID WHERE order_id IN ({$included_order_ids}) ", ARRAY_A ); /* phpcs:enable */ return $coupons; }