Month: October 2016

Get Product id from order id in Woocommerce

If you want to get Product id from order id in Woocommerce then fetch order details.

$order = new WC_Order( $order_id );
$items = $order->get_items();

then if you loop through them, you can get all the relevant data:

foreach ( $items as $item ) {
    $product_name = $item['name'];
    $product_id = $item['product_id'];
    $product_variation_id = $item['variation_id'];
}

Have any doubt, then comment here!

Get list of all woocommerce orders by date

If you want to get list of all woocommerce orders by date then using below code. Here change the value of $your_date by yourself.
Assign particular date to $your_date. This code will return the list of woocommerce orders placed in a particular date.

	$your_date = '2016-09-23';
	$args = array(
			'post_type' => 'shop_order',
			'post_status' => 'publish',
			'posts_per_page' => -1,
			'date_query'=> array(
					'after' => $your_date,
					'inclusive' => true,
					)
		);
	$orders = get_posts($args);

Have any doubt, then comment here!