Ask your WordPress questions! Pay money and get answers fast! (more info)

Fetch data, and write it as entries to a registered user profile WordPress


I use Cart66, and when a user has made a purchase, I want to write some data to his Wordpress user profile. That i believe goes into wp_usermeta

I will paste the function in the receipt.php file, which fires after a purchase. On that page and file, all information is already retrieved from the database and cart66's tables. So it is just a matter of pulling them, and then writing it to the user's meta.

The information that needs to be written are:

1: HREF link to the receipt. This i'll echo later on as a link for them to click on.
2: Product name. To later echo all the products bought
3: Save the grand total value, to later echo the total amount a customer has spent in the shop
4: Quantity, to later echo the total amount of items the customer has bought in the shop

This should not be so hard to get, since everything is already written and available on the receipt page of cart66.

I'm going to take a wild guess and show what code probably matches what i need.

<strong> Product name could be </strong>= $product->load($item->product_id);
<strong> Quantity could be</strong> = $item->quantity;

<strong>The order total could be</strong> = $order->total
<strong>Href to receipt is maybe this</strong> =
if($product->isDigital()) {
$receiptPage = get_page_by_path('store/receipt');
$receiptPageLink = get_permalink($receiptPage);
$receiptPageLink .= (strstr($receiptPageLink, '?')) ? '&duid=' . $item->duid : '?duid=' . $item->duid;
echo '<br/><a class="download-link" href="' . $receiptPageLink . '">' . __('Download', 'cart66') . '</a>';

After that is written, i just need to echo each individual value within my theme.

The values should be multiple friendly. For example, 1 href link to his receipt, and if he orders again 1 month later, a second receipt should be added, to echo them as a list.
Same for product names. And the total value, and quantity should also be able to increment it's values.

Answers (2)


ellvix answers:

You may want to attach the id of the cart66_order_items table instead of that info, since there could be multiple products and multiple pages attached to a single reciept. Therefore, I'd recommend this:

// put this in reciept.php where order is complete and $duid is available
global $user_ID ;
add_user_meta ( $user_ID, 'order_item_key', $duid ) ;

However, if you want to go with your current setup, do this:

// put in reciept.php where order is complete and $item is available

$receiptPage = get_page_by_path('store/receipt');
$receiptPageLink = get_permalink($receiptPage);
$receiptPageLink .= (strstr($receiptPageLink, '?')) ? '&duid=' . $item->duid : '?duid=' . $item->duid;
$qty = $item->quantity ;
$gTotal = $item->product_price * $qty ;
$prodName = $item->description ;

global $user_ID ;
add_user_meta ( $user_ID, 'reciept_link', $receiptPageLink ) ;
add_user_meta ( $user_ID, 'product_name', $prodName ) ;
add_user_meta ( $user_ID, 'grand_total', $gTotal ) ;
add_user_meta ( $user_ID, 'qty', $qty ) ;

Let me know if you need specific locations to put this code.

oomskaap comments:

The above code works perfectly. Thanks


Susanta K Beura answers:

I'll be happy to help you. Lets discuss and get it done va skype. My skype id is susanta.k

Thank you.

Susanta K Beura