All Resources

Send Easy Digital Downloads Purchase Data to Convertkit

In this simple Easy Digital Downloads / Convertkit integration, we’ll be subscribing users to Convertkit tags based on what downloads the customer purchases.

Convertkit Setup

In this integration, we’ll be hardcoding the tag IDs that we want to pass to the Convertkit API.

  • Copy your API key from the Convertkit account page.
  • Next, if you haven’t setup the tags you want to subscribe users to yet, do that by going to Subscribers > Create a Tag in the sidebar.
  • Copy the tag IDs of the tags you’re going to use by clicking on the tag link and noting the numerical ID in the URL bar.

Easy Digital Downloads Setup

We’re also going to hardcode the download IDs that we want to tie to a Convertkit tag. In our example, the EDD download with an ID of 321 will be mapped to the Convertkit tag with an ID 4879234 and so on.

To get the download IDs you want to use, just go to Downloads in your WordPress admin and hover over the Downloads you want to use.

The Completed Code

Make sure to update the following items

  • Change the CK_API_KEY constant to your Convertkit API key
  • Map the correct EDD Download ID to the Convertkit tag ID
  • Place the code in your functions.php or create a functionality plugin.
<?php
/***
Update Convertkit email with a Convertkit tag based on EDD download ID
Conditionally set Convertkit tag ID based on EDD download ID
***/
add_action( 'edd_complete_purchase', 'drw_update_ck_after_edd_purchase' );
function drw_update_ck_after_edd_purchase( $payment_id ) {
$edd_payment = new EDD_Payment($payment_id);
$email = $edd_payment->email;
$cart_items = edd_get_payment_meta_cart_details( $payment_id );
foreach ( $cart_items as $download ) {
$download_id = $download['id'];
if ( 321 == $download_id ) {
$ck_tag_id = 4879234;
drw_update_ck_subscriber( $email, $ck_tag_id, 'subscribe' );
} elseif( 430 == $download_id ) {
$ck_tag_id = 4879234;
drw_update_ck_subscriber( $email, $ck_tag_id, 'subscribe' );
}
}
}
<?php
/***
Define Convertkit API key
***/
define('CK_API_KEY', 'your_convertkit_api_key_here');
/***
Send subscriber data to Convertkit
$email str customer email address to send to CK
$endpoint str 'subscribe', 'unsubscribe'
***/
function drw_update_ck_subscriber( $email, $ck_tag_id, $endpoint = null ) {
if ( null == $endpoint ) $endpoint = 'subscribe';
//Add extra fields here if necessary
$args = array(
'email' => $email,
);
$request = wp_remote_post(
'https://api.convertkit.com/v3/tags/' . $ck_tag_id . '/'.$endpoint.'?api_key='.CK_API_KEY,
array(
'body' => $args,
'timeout' => 15,
)
);
if( ! is_wp_error( $request ) && 200 == wp_remote_retrieve_response_code( $request ) ) {
$return = true;
}
}

There are a ton of ways to modify this basic integration to fit your specific needs. Here are a few ideas.

Subscribe customers to one Convertkit tag

Create a “customer” tag in Convertkit, and just send all customers from EDD to that tag.

<?php
add_action( 'edd_complete_purchase', 'draw_update_ck_with_customer_tag' );
function draw_update_ck_with_customer_tag( $payment_id ) {
$ck_customer_tag_id = 1234;
$edd_payment = new EDD_Payment($payment_id);
$email = $edd_payment->email;
drw_update_ck_subscriber( $email, $ck_customer_tag_id, 'subscribe' );
}

Use EDD Download name as Convertkit tag

A more advanced integration would be to use a purchased EDD Download name as a Convertkit tag. In other words, a customer purchasing [Download Name ABC] would be subscribed to the Convertkit tag [Download Name ABC]. I won’t provide code for this option, but the basics would be to:

  • Loop through each download ID in the purchase like in the first example
  • Grab all Convertkit tags using the tags endpoint (GET)
  • If a given Download name matches one of the Convertkit tags, subscribe the user to that tag ID
  • If a given Download name doesn’t match the existing Convertkit tags, create the tag programmatically using the tags endpoint (POST)
  • Finally, subscribe the user to the newly created Convertkit tag after receiving the new tag ID in the previous response

Hopefully this give you some ideas on how to integrate Easy Digital Downloads data with Convertkit, and just how easy it is to do.

September 19, 2020 WordPress Development