admin管理员组

文章数量:1122832

I'm new to building websites but I have figured out something. Any help to get me forward would be highly appreciated!

I have a WP site with WhoCommerce. I have managed to get a working login functionality but now I would like to display user specific information in the users own profile page.

I would like to get the following user specific information to display: Date of puchase - puchased service - how many puchased services

I have tried something like:

<?php
global $wpdb;
if ( is_user_logged_in() ) {
global $current_user;
get_currentuserinfo();
echo $current_user->display_name . ' Hi: ';} 

$currentUser    = get_current_user_id();

$customers = $wpdb->get_results("SELECT * FROM wp_wc_order_product_lookup . currentUser”);
?>

<table class="table table-hover">

<?php foreach($customers as $customer){ ?>

<tr>
 <td><center><?php echo $customer->date_created; ?></center></td>
//etc.

</tr>

<?php } ?>

How should I change my code to get this user specific information displayed?

I'm new to building websites but I have figured out something. Any help to get me forward would be highly appreciated!

I have a WP site with WhoCommerce. I have managed to get a working login functionality but now I would like to display user specific information in the users own profile page.

I would like to get the following user specific information to display: Date of puchase - puchased service - how many puchased services

I have tried something like:

<?php
global $wpdb;
if ( is_user_logged_in() ) {
global $current_user;
get_currentuserinfo();
echo $current_user->display_name . ' Hi: ';} 

$currentUser    = get_current_user_id();

$customers = $wpdb->get_results("SELECT * FROM wp_wc_order_product_lookup . currentUser”);
?>

<table class="table table-hover">

<?php foreach($customers as $customer){ ?>

<tr>
 <td><center><?php echo $customer->date_created; ?></center></td>
//etc.

</tr>

<?php } ?>

How should I change my code to get this user specific information displayed?

Share Improve this question edited Nov 13, 2019 at 14:33 Chetan Vaghela 2,3984 gold badges10 silver badges16 bronze badges asked Nov 13, 2019 at 10:10 tommitommi 1 2
  • WooCommerce already has a profile page with all this information. Why do you need to do it yourself? – Jacob Peattie Commented Nov 13, 2019 at 10:35
  • I'm using the profile page but in the end I would need to make some calculations based on made orders and the price to present the customers with this kind of information. – tommi Commented Nov 13, 2019 at 13:44
Add a comment  | 

1 Answer 1

Reset to default 0

WooCommerce uses a custom post type “shop_order” to store orders. This means that the orders will be stored in the wp_posts database table with the post_type column set to shop_order


SELECT ID, post_author, post_date, post_status, post_type FROM wp_posts
WHERE post_type = 'shop_order'

WooCommerce stores a large portion of the order related data as post meta. Once you have the order ID, you can find the customer data by searching the wp_postmeta table by the order ID

SELECT * FROM wp_postmeta WHERE post_id = $currentUser

Find more info https://usersinsights.com/woocommerce-customer-database/

本文标签: woocommerce offtopicHow to get users data from wordpress woocomerce database to display