We’ve recently been working on a horoscopes website for one of our clients that has some content that is for members only. The Cart66 WordPress eCommerce has been great for handling the PayPal subscriptions but I had to add some custom functionality so that new members on certain levels would be automatically signed up to a mailing list which is handled by Constant Contact.
Cart66 actually has Constant Contact integration which adds an “opt-in” style mailing list signup that is added to the checkout which would normally work fine for most eCommerce sites however I we needed to make the signup compulsory for the user and to do it seamlessly without the user knowing that this has occurred so they receive the daily emails that they have purchased.
The undocumented cart66_after_order_saved hook
I hunted around the Cart66 support section to see if Cart66 had any hooks built in and I found out that there are four hooks which aren’t documented at this stage. One of these hooks is the cart66_after_order_saved hook which I decided to use for the additional functionality I required. I started with a function and after hunting through the Cart66 code I found that the $orderInfo array would get passed into the function.
function sennza_add_to_constant_contact($orderInfo){
/* This is where my logic will go*/
}
add_action( 'cart66_after_order_saved' , 'sennza_add_to_constant_contact' );
What’s in the $orderInfo array?
Next up I need to find out what the contents of the $orderInfo array are so I used print_r($orderInfo) to echo them out. The array contents are as follows:
Array ( [ship_first_name] => Test [ship_last_name] => User [ship_address] => 888 Brunswick Street [ship_address2] => [ship_city] => NEW FARM [ship_state] => Queensland [ship_zip] => 4005 [ship_country] => Australia [bill_first_name] => Test [bill_last_name] => User [bill_address] => [bill_address2] => [bill_city] => [bill_state] => [bill_zip] => [phone] => [email] => test@here.com [coupon] => none [tax] => [shipping] => 0.00 [subtotal] => 0 [total] => 0.00 [non_subscription_total] => 0.00 [trans_id] => MT-ZLPLDQNSJC7JGE [status] => New [ordered_on] => 2012-01-31 13:06:05 [shipping_method] => None [account_id] => 2829 [ip] => 124.171.95.111 [discount_amount] => 0 [id] => 4987 )
Alright, stop… Database time!
Now I knew that $orderInfo[account_id] was the newly generated Cart66 Account ID I looked into the database tables in phpmyadmin and realised that I needed to use this id to find out the membership level (or ‘feature_level’ as Cart66 names it).
function sennza_add_to_constant_contact($orderInfo){
global $wpdb;;
$account_id = $orderInfo[account_id];
$table_name = $wpdb->prefix . "cart66_account_subscriptions";
$sql = "SELECT `feature_level` FROM $table_name WHERE `account_id` = $account_id";
$account_type = $wpdb->get_var($sql);
/* User $account_type to perform the Constant Contact Logic */
}
add_action( 'cart66_after_order_saved' , 'sennza_add_to_constant_contact' );
Take note of the $wpdb class that I’ve interacted with in this function. The $wpdb class has a massive amount of power that makes interacting with the WordPress database a breeze! In this case I only wanted to pull out one variable so I’ve used the $wpdb->get->var function.
After that I ended up reading some of the Constant Contact API documentation to generate some XML to send to Constant Contact so that the subscribers were instantly added to the appropriate mailing list.
NB: I haven’t included the additional logic for the Constant Contact API as it is very site specific and I just wanted to document the data that the cart66_after_order_saved hook receives for other Cart66 developers

Just wondering what these other 3 undocumented actions are. Do you remember, I can’t find anything on them and I’m hoping there is one for after a product is deleted.
Thanks!
Ah, found them…. in case you want to publish
cart66_after_add_to_cart
cart66_after_update_cart
cart66_after_remove_item
cart66_after_order_saved
Haha you beat me to it. I was just about to post those for you
Im trying to use this hook but cant seem to get it working.
Here is my code: Im just testing right now to see if I can even get and echo appear during the checkout stage. I go through the entire buying process via paypal sandbox but do not see this echoed anywhere. I tried it with and without the $orderInfo parameter passed but no avail. Am I doing something wrong here?
woops, pastebin did not work, here is the code:
function add_to_wishlist_member(){
echo ‘oonga boonga’;
}
add_action( ‘cart66_after_order_saved’ , ‘add_to_wishlist_member’ );
Woops I figured it out, turns out the print_r must of been happening somewhere inbetween the pages loading, hence I wasnt seeing it. I added a test wp_insert_post inside the hook and it created a post, so looks like it was getting inside that hook after all.
Thanks for the code!
Glad you got it sorted! I was asleep when you posted your comments
Quick note: your form is a bit jacked in the latest Firefox…may want to have a look
On topic (mostly): trying to implement wp_insert_post() to handle multiple post inserts that work well with cart66 postmeta…any ideas on that…should this be a new thread?
Hey Will,
Thanks for the heaps up on our comment form. Just fixed that then. I have have to do some work on our site this week as it’s still needs some polish to some areas
In terms of your question, are you looking to manipulate the taxonomies for the Feature levels? So you’d be inserting multiple posts and on that insertion adding access for certain feature levels or are you trying to do something different?