How can I find out what items a user has purchased?

I’m using WordPress E-Commerce (get shopped) and would like to get a list of items that a user has purchased, just a list of post IDs would be perfect. Is there any way for me to get this?

It must be stored somewhere.. has anyone attempted this before?

Related posts

Leave a Reply

2 comments

  1. Query the table wp_wpsc_purchase_logs, it contains all information about previous purchases.

    add this to your themes functions.php:

    /*********************************************************
    Get purchased articles by user_id or for the current user
    *********************************************************/
    function haet_recently_bought_articles($user_id=0){
        if($user_id==0)
            $user_id=get_current_user_id();
    
        //only if there is an active user, otherwise we would get all purchased items from unregistered users
        if($user_id>0) {
            global $wpdb;
            $sql = $wpdb->prepare("
                    SELECT prodid, name, price
                    FROM `".$wpdb->prefix."wpsc_cart_contents` 
                    INNER JOIN `".$wpdb->prefix."wpsc_purchase_logs` ON purchaseid = ".$wpdb->prefix."wpsc_purchase_logs.id
                    WHERE  user_ID = %d
                    ORDER BY date DESC"
                    ,$user_id);
            $items = $wpdb->get_results($sql,ARRAY_A);
            return $items;
        }
        return null;
    }
    

    and add the following lines to the template to show the products e.g. page-.php

    <ul class="articles">
        <?php 
        $articles = haet_recently_bought_articles();
        foreach($articles AS $article){
            echo '<li>'.$article['name'].'</li>';
        }
        ?>
    </ul>
    
  2. global $wpsc_cart;  
    

    This is the global variable , looping through this will get all the info ie products added in cart by user, just do

     print_r( $wpsc_cart; )
    

    and you will come to know.