Pass PHP POST data to a WordPress page with permalink rewrites on

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

Read More
$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

Related posts

Leave a Reply

1 comment

  1. To catch posted data, use wordpress’s ‘init’ action to catch posted data, for example

    add_action('init', 'ur_form_process_fun');
    
    function ur_form_process_fun(){
     if(isset($_POST['unique_hidden_field'])) {
       // process $_POST data here
     }
    }
    

    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. 🙂