• Hi , first of all really thanks for this great plugin .

    Could any one please give examples and uses of WC_Query .

    For listing the orders i used WP_query, because i don’t know how to use WC_Query .

    ` $args = array(

    ‘post_type’ => ‘shop_order’,

    ‘post_status’ => ‘publish’
    );
    $loop=new WP_Query($args);
    while($loop->have_posts()): $loop->the_post();
    $order_id=get_the_ID();
    $order = new WC_Order($order_id);

    ..details i fetched from query ..

    endwhile ;`
    `
    this way i write the code

    https://wordpress.org/plugins/woocommerce/

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter ramtm

    (@ramtm)

    i need to get all orders that belongs to or contain A PRODUCT. ie if product1 is my product name then i need to get all orders in the loop that contain this product . For to get order detail i use the following query

    $args = array(
    
                        'post_type'         => 'shop_order',
    
                        'post_status'       => 'publish'
                             );
              $loop=new WP_Query($args);
             while($loop->have_posts()): $loop->the_post();
             $order_id=get_the_ID();
             $order = new WC_Order($order_id);
    
            ..details i fetched from query ..
    
                endwhile ;

    to get item details i can use $order->get_items(); I want to

    (1) it is the best method to fetch order details in the loop ?

    (2)How to fetch orders that belongs to product1 [where product1 is my product name ] .?

    Please help .

    Plugin Author Mike Jolley (a11n)

    (@mikejolley)

    WC_Query is not used directly. Continue to use WP_Query

    Thread Starter ramtm

    (@ramtm)

    ok . Could you please tell me How to create Woocoomerce order query with product name?

    i need to get all orders that belongs to or contain A PRODUCT. ie if product1 is my product name then i need to get all orders in the loop that contain this product . For to get order detail i use the following query

    $args = array(
    
                        'post_type'         => 'shop_order',
    
                        'post_status'       => 'publish'
                             );
              $loop=new WP_Query($args);
             while($loop->have_posts()): $loop->the_post();
             $order_id=get_the_ID();
             $order = new WC_Order($order_id);
    
            ..details i fetched from query ..
    
                endwhile ;

    to get item details i can use $order->get_items(); I want to

    (1) it is the best method to fetch order details in the loop ?

    (2)How to fetch orders that belongs to product1 [where product1 is my product name ] .?

    Please help .

    Plugin Author Mike Jolley (a11n)

    (@mikejolley)

    This is not straightforward because the data spans multiple tables. Get_posts/WP_Query is not suitable.

    You would first need to query order line items for the product id, then pass those order ids to get_posts or WP_query.

    Thread Starter ramtm

    (@ramtm)

    but that’s make too much time to exicute , if i have many orders .

    Thread Starter ramtm

    (@ramtm)

    please give the sample code .

    Plugin Author Mike Jolley (a11n)

    (@mikejolley)

    but that’s make too much time to exicute , if i have many orders

    yes it would. But thats the only way to do it right now. We are looking at ways to use custom tables in the future.

    I don’t provide customisations/code sorry. Take a look at the core reports classes which do similar things.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘WC_Query example’ is closed to new replies.