Skip to content

Instantly share code, notes, and snippets.

@amdrew
Last active January 1, 2016 04:19
Show Gist options
  • Select an option

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

Select an option

Save amdrew/8090796 to your computer and use it in GitHub Desktop.
EDD Social Discounts - If you add the shortcode to your purchase confirmation page, and only 1 product is purchased, it will share the URL to that product in each of the social networks.
<?php
function sumobi_social_discounts_purchase_confirmation_url( $url ) {
global $edd_options;
// make sure we are on the EDD Purchase Confirmation page, else return
if ( ! ( isset( $edd_options['success_page'] ) && is_page( $edd_options['success_page'] ) ) )
return;
// get the purchase session
$purchase_session = edd_get_purchase_session();
// get purchase key
$purchase_key = $purchase_session['purchase_key'];
// get payment_id from purchase key
$payment_id = edd_get_purchase_id_by_key( $purchase_key );
// get cart using payment ID
$cart = edd_get_payment_meta_cart_details( $payment_id, true );
// get first download from cart
$first_download = array_values( $cart );
$first_download = array_shift( $first_download );
// get the first download's ID
$first_download_id = $first_download['id'];
// set URL to the site's URL if more than 1 product
if( count( $cart ) > 1 ) {
$url = site_url();
}
// only 1 product, set the URL to be the URl of product
else {
$url = post_permalink( $first_download_id );
}
// return URL
return $url;
}
add_filter( 'edd_social_discounts_share_url', 'sumobi_social_discounts_purchase_confirmation_url' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment