• Resolved loopforever

    (@loopforever)


    Hello,
    In a project I’m working on, I created a new section on the My Account page (like Dowloands). But here, I can’t get the order number.

    Can I access the order code with the current customer id?

    get_current_user_id();

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi @loopforever,

    This should work:

    $customer = wp_get_current_user(); // do this when user is logged in
    $customer_orders = get_posts(array(
      'numberposts' => -1,
      'meta_key' => '_customer_user',
      'orderby' => 'date',
      'order' => 'DESC',
      'meta_value' => get_current_user_id(),
      'post_type' => wc_get_order_types(),
      'post_status' => array_keys(wc_get_order_statuses()), 
      'fields' => 'ids',
    ));
    
    $user_orders = array(); //
    foreach ($customer_orders as $orderID) {
      $orderObj = wc_get_order($orderID);
      $user_orders[] = array(
        "orderID" => $orderObj->get_id(),
        "orderTotal" => $orderObj->get_total(),
        "orderDate" => $orderObj->get_date_created()->date_i18n('Y-m-d h:i:s'),
      );
    }
    echo '<pre>';
    var_dump($user_orders);
    echo '</pre>';

    Hi @loopforever

    We’ve not heard back from you in a while, so I’m marking this thread as resolved. If you have further questions, please feel free to open a new topic.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to Reach Order Code with Current User ID?’ is closed to new replies.