"query orders by products woocommerce" Code Answer's
You're definitely familiar with the best coding language TypeScript that developers use to develop their projects and they get all their queries like "query orders by products woocommerce" answered properly. Developers are finding an appropriate answer about query orders by products woocommerce related to the TypeScript coding language. By visiting this online portal developers get answers concerning TypeScript codes question like query orders by products woocommerce. Enter your desired code related query in the search bar and get every piece of information about TypeScript code related question on query orders by products woocommerce.
query orders by products woocommerce
/**
* Get All orders IDs for a given product ID.
*
* @param integer $product_id (required)
* @param array $order_status (optional) Default is 'wc-completed'
*
* @return array
*/
function get_orders_ids_by_product_id( $product_id, $order_status = array( 'wc-completed' ) ){
global $wpdb;
$results = $wpdb->get_col("
SELECT order_items.order_id
FROM {$wpdb->prefix}woocommerce_order_items as order_items
LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta ON order_items.order_item_id = order_item_meta.order_item_id
LEFT JOIN {$wpdb->posts} AS posts ON order_items.order_id = posts.ID
WHERE posts.post_type = 'shop_order'
AND posts.post_status IN ( '" . implode( "','", $order_status ) . "' )
AND order_items.order_item_type = 'line_item'
AND order_item_meta.meta_key = '_product_id'
AND order_item_meta.meta_value = '$product_id'
");
return $results;
}
Source: stackoverflow.com
All those coders who are working on the TypeScript based application and are stuck on query orders by products woocommerce can get a collection of related answers to their query. Programmers need to enter their query on query orders by products woocommerce related to TypeScript code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about query orders by products woocommerce for the programmers working on TypeScript code while coding their module. Coders are also allowed to rectify already present answers of query orders by products woocommerce while working on the TypeScript language code. Developers can add up suggestions if they deem fit any other answer relating to "query orders by products woocommerce". Visit this developer's friendly online web community, CodeProZone, and get your queries like query orders by products woocommerce resolved professionally and stay updated to the latest TypeScript updates.