Created
May 26, 2015 23:03
-
-
Save jondcampbell/353e70c419882890308d to your computer and use it in GitHub Desktop.
Find all woocommerce orders that have a particular product_id in it. Returns an array of order ids.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
global $wpdb; | |
$sql = "SELECT order_id FROM {$wpdb->prefix}woocommerce_order_items WHERE order_item_id IN ( SELECT order_item_id FROM {$wpdb->prefix}woocommerce_order_itemmeta WHERE meta_key = '_product_id' AND meta_value = $product_id ) AND order_item_type = 'line_item'"; | |
$order_ids = $wpdb->get_col( $sql ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment