Skip to content

Instantly share code, notes, and snippets.

@amdrew
Created November 27, 2013 21:21
Show Gist options
  • Select an option

  • Save amdrew/7683426 to your computer and use it in GitHub Desktop.

Select an option

Save amdrew/7683426 to your computer and use it in GitHub Desktop.
Add a twitter share button to EDD's purchase confirmation page.
<?php
function edd_custom_success_page_share() {
global $edd_receipt_args, $edd_options;
$payment = get_post( $edd_receipt_args['id'] );
$meta = edd_get_payment_meta( $payment->ID );
$cart = edd_get_payment_meta_cart_details( $payment->ID, true );
$first_download = array_values( $cart );
$first_download = array_shift( $first_download );
$name = $first_download['name'];
// make sure a success page has been set in the options and we're on it
if ( isset( $edd_options['success_page'] ) && is_page( $edd_options['success_page'] ) ) {
// more than 1 purchase
if( count($cart) > 1 ) {
$twitter_message = 'I just snagged ' . $name . ' and other awesome stuff from';
}
// only 1 purchase
else {
$twitter_message = 'I just snagged ' . $name . ' from';
}
?>
<h2>We really appreciate your support!</h2>
<a href="https://twitter.com/share" class="twitter-share-button" data-count="vertical" data-url="http://sumobi.com" data-text="<?php echo $twitter_message; ?>" data-via="sumobi_" data-related="sumobi_">Share</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
<?php }
}
add_action( 'edd_payment_receipt_after', 'edd_custom_success_page_share' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment