0

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?

  • WooCommerce already has a profile page with all this information. Why do you need to do it yourself? – Jacob Peattie Nov 13 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 Nov 13 at 13:44
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/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.