Last active
October 30, 2020 08:34
-
-
Save bramchi/9a91b7f79c644a23e3731bbde78795b7 to your computer and use it in GitHub Desktop.
Get all WooCommerce orders from Wordpress that have a Local Pickup Plus appointment
This file contains hidden or 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
function get_orders_with_pickup_appointment() { | |
global $wpdb; | |
$sql = " | |
SELECT | |
`items`.`order_id` | |
FROM | |
`{$wpdb->prefix}woocommerce_order_items` AS `items` | |
INNER JOIN | |
`{$wpdb->prefix}woocommerce_order_itemmeta` AS `itemmeta` | |
ON | |
`items`.`order_item_id` = `itemmeta`.`order_item_id` | |
WHERE | |
`items`.`order_item_name` IN('Local Pickup') | |
AND | |
`itemmeta`.`meta_key` IN('_pickup_appointment_start') | |
GROUP BY | |
`items`.`order_item_id` | |
"; | |
return array_map(function ( $data ) { | |
return wc_get_order( $data->order_id ); | |
}, $wpdb->get_results( $sql ) ); | |
} | |
$orders = get_orders_with_pickup_appointment(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment