Checkout Fields Manager – Getting Meta Data
The Checkout Fields Manager extensionallows you to make custom fields for your checkout form. This makes it easy to gather data from your customers. You can see it easily on the Payment History page, but what if you want to have it printed on the receipt for the customer to see? This document will help with that.
Radio Buttons Example
In this example we’re going to use a custom radio buttons field, titled “Are you happy with this purchase process?”. The meta key for this field was automatically generated as are_you_happy_with_this_purchase_process
, and we’ve simply made a Yes/No answer option. See below.
Since we’re going to be rendering this information on the customer receipt, let’s take a look at that template. The template we want is called shortcode-receipt.php. Read our docs on how to move this template to your theme.
Near the top of that file you’ll find this code:
$payment = get_post( $edd_receipt_args['id'] );
which creates an object for this payment. In the rest of this file we can now find the ID for this payment under $payment->ID
.
In the example above the Meta Key is are_you_happy_with_this_purchase_process
. Now that we have both the ID and the Meta Key we can get the value with this code:
get_post_meta( $payment->ID, 'are_you_happy_with_this_purchase_process', true )
Note: the ‘true’ in the example above indicates that we’re expecting a single value from get_post_meta(). Checkout Fields Manager returns a single value for all field types it offers.
Printing to the Receipt
In the above example we got the value we wanted, but now we want to render it nicely in receipts. In shortcode-receipt.php
you’ll find a HTML table with a CSS ID of edd_purchase_receipt. You can copy this table and change the values. Here’s an example of a table header:
ID ), 'are_you_happy_with_this_purchase_process', true ) ) ); ?> | |
ID, 'favorite_animal', true ) as $animal ) { $animals .= ' |
ID ), 'are_you_happy_with_this_purchase_process', true ) ) ); ?> | |
ID, 'favorite_animal', true ) as $animal ) { $animals .= ' |
Which will look like this:
Key Points
- To render Custom Fields answers on your receipts, copy the shortcode-receipt.php file to your theme and put your code in there
- Getting the data is simply doing a get_post_meta() call on the Meta Key provided in you the admin area
- All keys from Custom Fields Manager are stored as singles in the post_meta table.
Note: Easy Digital Downloads does not provide support for custom coding/development. If needed we recommend hiring a developer through Codeable make the custom changes you need.