Created
November 7, 2018 21:24
-
-
Save eto4detak/36c40b4303ba07f161ed334691f74cb9 to your computer and use it in GitHub Desktop.
woo php order get metadata
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
<?php | |
//получить Id заказов бронирования авто | |
public static function get_orders_ids($order_status = array('wc-completed')){ | |
global $wpdb; | |
$product_id = self::$settings['woo_id_product']; | |
$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; | |
} | |
public static function get_order_time($value='') | |
{ | |
$orders_ids = self::get_orders_ids(); | |
foreach ($orders_ids as $order_id) { | |
$order = wc_get_order( $order_id ); | |
foreach( $order->get_items() as $item_id => $item_product ){ | |
// Get the common data in an array: | |
$item_product_data_array = $item_product->get_data(); | |
// Get the special meta data in an array: | |
$item_product_meta_data_array = $item_product->get_meta_data(); | |
// Get the specific meta data from a meta_key: | |
$meta_value = $item_product->get_meta( 'Start location', true ); | |
return $meta_value; | |
// echo '<pre>'; | |
// var_dump($meta_value); | |
// echo '</pre>'; | |
foreach ($item_product_meta_data_array as $key => $meta) { | |
// echo '<pre>'; | |
// var_dump($key); | |
// var_dump($meta->get_data()); | |
// echo '</pre>'; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment