Title: Using short code in template file
Last modified: April 29, 2021

---

# Using short code in template file

 *  [biffa](https://wordpress.org/support/users/biffa/)
 * (@biffa)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/using-short-code-in-template-file/)
 * Hi All,
 * I am creating a template file for the thank you page using do_shortcode and [
   accept_stripe_payment_checkout]. This all works fine for the standard output,
   however I need to retrieve the transaction ID as I need it to add some more data
   about the user to the database.
 * Is it possible to add the ‘transaction_id’ to the shortcode as a parameter instead
   of using {transaction_id} in the body text? Alternatively is there a way to retrieve
   an array of the data outputted from your shortcode method?
 * Thanks

Viewing 10 replies - 1 through 10 (of 10 total)

 *  [Ovidiu](https://wordpress.org/support/users/ovidiubica/)
 * (@ovidiubica)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/using-short-code-in-template-file/#post-14382770)
 * That’s not the best place to grab the payment information as its built just to
   display the checkout result to the user.
    The right place to hook and get checkout
   data is `do_action( 'asp_stripe_payment_completed', $data, $data['charge'] );`
 * If you hook in this location and dump $data, you should find all the information
   you need.
 *  Thread Starter [biffa](https://wordpress.org/support/users/biffa/)
 * (@biffa)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/using-short-code-in-template-file/#post-14383252)
 * Hi, thanks for the quick response.
 * I’ve added this to the funtions.php file:
 *     ```
       add_action('asp_stripe_payment_completed', 'asp_after_txn_callback', 10 ,2);
       function asp_after_txn_callback ($post_data, $charge)
       {
           //Do stuff
           //$charge is the Stripe charge object.
           //print_r($post_data);//Lets see what info is in this array.
       }
       ```
   
 * And added the code you suggested above to my template file. However I’m getting
   several errors:
    Notice: Undefined variable: data Notice: Trying to access array
   offset on value of type null
 *  [Ovidiu](https://wordpress.org/support/users/ovidiubica/)
 * (@ovidiubica)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/using-short-code-in-template-file/#post-14383351)
 *     ```
       add_action('asp_stripe_payment_completed', 'asp_after_txn_callback');
       function asp_after_txn_callback ($data)
       {
          echo "<pre>";
       var_dump($data);
       echo "</pre>";
       }
       ```
   
    -  This reply was modified 5 years, 1 month ago by [Ovidiu](https://wordpress.org/support/users/ovidiubica/).
 *  Thread Starter [biffa](https://wordpress.org/support/users/biffa/)
 * (@biffa)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/using-short-code-in-template-file/#post-14383639)
 * ok that makes sense. However, var_dump($data[‘charge’]) works but var_dump($data[‘
   txn_id’]) returns NULL
 *  [Ovidiu](https://wordpress.org/support/users/ovidiubica/)
 * (@ovidiubica)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/using-short-code-in-template-file/#post-14387157)
 * Where exactly are you checking? If its front-end, its possible it doesn’t pause
   on your variables. Use a PHP IDE to debug the code.
    The ID you’re looking for
   should be returned within $data[‘charge’][‘id’] and within $data[‘txn_id’]
 *  Thread Starter [biffa](https://wordpress.org/support/users/biffa/)
 * (@biffa)
 * [5 years ago](https://wordpress.org/support/topic/using-short-code-in-template-file/#post-14391418)
 * ID should be returned but isn’t. This is the code I have.
 * In functions/fields.php :
 *     ```
       add_action('asp_stripe_payment_completed', 'asp_after_txn_callback');
       function asp_after_txn_callback ($data)
       { 
       var_dump($data['charge']['id']); 
       }
       ```
   
 * In my template file stripe_success.php
    do_action( ‘asp_stripe_payment_completed’,
   $data, $data[‘charge’] );
 * This is the errors that are returned:
 *     ```
       Notice: Undefined variable: data in /home/hp3-linc1-nfs2-z/400/506400/user/htdocs/wp-content/themes/champs/stripe_success.php on line 22
   
       Notice: Undefined variable: data in /home/hp3-linc1-nfs2-z/400/506400/user/htdocs/wp-content/themes/champs/stripe_success.php on line 22
   
       Notice: Trying to access array offset on value of type null in /home/hp3-linc1-nfs2-z/400/506400/user/htdocs/wp-content/themes/champs/stripe_success.php on line 22
   
       Notice: Trying to access array offset on value of type null in /home/hp3-linc1-nfs2-z/400/506400/user/htdocs/wp-content/themes/champs/functions/fields.php on line 1431
   
       Notice: Trying to access array offset on value of type null in /home/hp3-linc1-nfs2-z/400/506400/user/htdocs/wp-content/themes/champs/functions/fields.php on line 1431
       NULL
       ```
   
 * If I remove [‘id’] it works and returns the full array from Stripe. But I need
   the transaction from that array.
 *  Thread Starter [biffa](https://wordpress.org/support/users/biffa/)
 * (@biffa)
 * [5 years ago](https://wordpress.org/support/topic/using-short-code-in-template-file/#post-14391453)
 * Basically what I’m trying to do is check if the payment went through and returned
   as true. That way I can update the database with the details of the user so I
   know they have paid. I was hoping to do this by adding the transaction ID to 
   the user meta. If this is not the best way to do this, please let me know a better
   way.
 * Thanks.
 *  [Ovidiu](https://wordpress.org/support/users/ovidiubica/)
 * (@ovidiubica)
 * [5 years ago](https://wordpress.org/support/topic/using-short-code-in-template-file/#post-14391850)
 * The do_action call is an existing hook inside the plugin right after payment 
   is confirmed. That’s where you’re hooking using your own add_action call to grab
   the payment data. You should read about WordPress actions and filters and how
   to use them to get/modify the data.
 *  Thread Starter [biffa](https://wordpress.org/support/users/biffa/)
 * (@biffa)
 * [5 years ago](https://wordpress.org/support/topic/using-short-code-in-template-file/#post-14393544)
 * I’m not having a problem getting the $data array, the problem is getting the 
   transaction ID from that array.
 *  [Ovidiu](https://wordpress.org/support/users/ovidiubica/)
 * (@ovidiubica)
 * [5 years ago](https://wordpress.org/support/topic/using-short-code-in-template-file/#post-14395602)
 * There’s no issue getting the transaction ID, the code is fine except the do_action
   call which shouldn’t be included anywhere in your code as that one should be 
   and is included within our plugin.
 * Put this into stripe-success.php or or theme’s functions.php and you should see
   the id (exit line stops the script execution so you can see the output since 
   you’re not using a PHP debugger).
 *     ```
       add_action('asp_stripe_payment_completed', 'asp_after_txn_callback');
       function asp_after_txn_callback ($data) {
       var_dump($data['txn_id']);
       exit();
       }
       ```
   

Viewing 10 replies - 1 through 10 (of 10 total)

The topic ‘Using short code in template file’ is closed to new replies.

 * ![](https://ps.w.org/stripe-payments/assets/icon-128x128.png?rev=2705524)
 * [Accept Stripe Payments](https://wordpress.org/plugins/stripe-payments/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/stripe-payments/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/stripe-payments/)
 * [Active Topics](https://wordpress.org/support/plugin/stripe-payments/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/stripe-payments/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/stripe-payments/reviews/)

## Tags

 * [shortcode](https://wordpress.org/support/topic-tag/shortcode/)
 * [templates](https://wordpress.org/support/topic-tag/templates/)

 * 10 replies
 * 2 participants
 * Last reply from: [Ovidiu](https://wordpress.org/support/users/ovidiubica/)
 * Last activity: [5 years ago](https://wordpress.org/support/topic/using-short-code-in-template-file/#post-14395602)
 * Status: not resolved