How can I get customer details from an order in WooCommerce?

前端 未结 15 1535
北海茫月
北海茫月 2020-12-01 00:10

I have a function that does this:

$order = new WC_Order($order_id);
$customer = new WC_Customer($order_id);

How can I get customer details fr

15条回答
  •  借酒劲吻你
    2020-12-01 00:57

    WooCommerce "Orders" are just a custom post type, so all the orders are stored in wp_posts and its order information in stored into wp_postmeta tables.

    If you would like to get any details of WooCommerce's "Order" then you can use the below code.

    $order_meta = get_post_meta($order_id); 
    

    The above code returns an array of WooCommerce "Order" information. You can use that information as shown below:

    $shipping_first_name = $order_meta['_shipping_first_name'][0];
    

    To view all data that exist in "$order_meta" array, you can use the below code:

    print("
    ");
    print_r($order_meta);
    print("
    ");

提交回复
热议问题