Load Receipt Hook
Cart66 allows you to connect to the process of displaying the receipt so that you can programmatically collect the order data, parse it, and do something with it like synchronize your orders with a 3rd party application. There is a PHP helper function that accepts the order id for the order you want to work with and returns an associative array of the data for that order. Here is how it works.
The flow
When a customer successfully completes a purchase from your online store, the following steps are traversed:
- The customer selects what to purchase on your WordPress site
- The customer is transferred to your secure checkout page to enter billing information and complete the order
- The order is successfully processed with your payment gateway
- The customer is redirected back to your WordPress site to view the online receipt
The last step in the process is where this hook comes into play. You can connect to this event, receive the order id, and programmatically work with the order data (not including the credit card information).
The hook
cc_load_receipt
This hook passes the order id to the function you specify in your add_action() call.
This hook is fired every time a receipt is loaded. Keep in mind that a customer may visit his online receipt more than one time.
PHP helper function
CC::order_data($order_id)
This helper function accepts the order id as its only parameter and returns an associative array of the order data.
Array ( [order_number] => 350F6340B98454B2F3CA0B2F [subtotal] => 19.0 [contact] => Array ( [email] => demo@cart66.com [first_name] => Demo [last_name] => User ) [billing_address] => Array ( [street] => 1234 Test Dr [address2] => Suite 300 [city] => Richmond [state] => VA [zip] => 23227 [country] => US ) [shipping_address] => Array ( [street] => PO Box 224 [address2] => [city] => New Kent [state] => VA [zip] => 23124 [country] => US ) [items] => Array ( [0] => Array ( [name] => Archery Subscription [description] => Archery Subscription [quantity] => 1 [price] => 19.0 [total] => 19.0 ) ) )
Example usage
The easiest way to start using this hook is to include a code like this in your theme's functions.php file.
function process_order($order_id) { // Make sure the Cart66 class exists before attempting to use it if(class_exists('CC')) { $order_data = CC::order_data($order_id); /* Write code to do something with the order data */ } } add_hook('cc_load_receipt', 'process_order');
Of course, you could also create your own plugin that uses the same hook.
This functionality was introduced with version 1.7.1 of the Cart66 Cloud plugin.
Do you have an example to share using this hook? Email support@cart66.com and let us know how you have used the hook. We'd love to see what you have done with this and be able to share the code with others.