I’m working with an eCommerce gateway that passes transaction data back to my site after a completed sale via PHP POST data. I need to track this data with Google Analytics’ eCommerce event tracking, and present a thank-you page.
Currently, I have the eCommerce site sending customers to /thankyou.php, which has
$total = $_POST["Total"];
(among other fields) in the header. And then I use Google’s script to send the data to Analytics:
_gaq.push(['_addTrans',
"<?php echo $orderid; ?>", // order ID - required
"<?php echo $storename; ?>", // affiliation or store name
"<?php echo $total; ?>", // total - required
"", // tax
"", // shipping
"<?php echo $city; ?>", // city
"<?php echo $state; ?>", // state or province
"<?php echo $country; ?>" // country
]);
This works! Perfectly. The problem is : when I try and put the same code in WordPress’ header (or on a static page), none of the $_POST data comes through. All of the fields are blank. I’m assuming this is because I’m sending the data to something like “/thank-you/” instead of /thank-you.php.
Is there any way I can make a WordPress page deal with $_POST data in the same way a .php page would?
Thank you
To catch posted data, use wordpress’s ‘init’ action to catch posted data, for example
You can put this code in your plugins file or your theme’s functions.php file.
In above code ur_form_process_fun() function trigger at initializing stage of wordpress.
unique_hidden_field
can be one of the unique transaction field returened to your site.Hope this may solve your problem. 🙂