Created
July 19, 2017 00:05
-
-
Save ryanckulp/e56dbb91d58f81fe85e5ea5412397a96 to your computer and use it in GitHub Desktop.
fomo checkout mapping for electronic digital downloads
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
function goFomo() { | |
// return early if inputs invalid | |
var first_name = jQuery('input[name="edd_first"]').val(); | |
var email = jQuery('input[name="edd_email"]').val(); | |
var products = jQuery('span.edd_checkout_cart_item_title'); | |
var title = jQuery(products[0]).text(); | |
var images = jQuery('.edd_cart_item_image'); | |
var image_url = jQuery(images[0]).find('img').attr('src'); | |
// uncomment to prevent blank values, or use 'default' filter | |
// if (!first_name || !email || !title) {return;} | |
params = {event: { | |
first_name: first_name, | |
email_address: email, | |
title: title, | |
image_url: image_url, | |
event_type_id: XXX | |
} | |
} | |
jQuery.ajax({ | |
url: 'https://www.usefomo.com/api/v1/applications/me/events', | |
method: 'POST', | |
contentType: 'application/json', | |
headers: { | |
"Authorization": "Token XXXXXXXX" | |
}, | |
data: JSON.stringify(params), | |
success: function(data) { | |
console.log("id: " + data.id); | |
console.log(data.message); | |
} | |
}) | |
} | |
jQuery('#edd_purchase_form').on('submit', goFomo) | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment