Last active
November 27, 2020 21:49
-
-
Save dryan1144/2c50949dbf227ed6cdd6bf98b3b80ae6 to your computer and use it in GitHub Desktop.
Easy Digital Downloads Developer Hooks
This file contains 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
<?php | |
/*** | |
edd_complete_purchase | |
$payment_id int ID of EDD payment object | |
Do something with payment data after purchase | |
https://docs.easydigitaldownloads.com/article/534-edd-complete-purchase | |
***/ | |
add_action( 'edd_complete_purchase', 'drw_enroll_after_purchase' ); | |
function drw_api_call_after_purchase( $payment_id ) { | |
$payment_meta = edd_get_payment_meta( $payment_id ); | |
$cart_items = edd_get_payment_meta_cart_details( $payment_id ); | |
$user_id = $payment_meta['user_info']['id']; | |
foreach ( $cart_items as $download ) { | |
//make API call | |
drw_update_email_api( $user_id, $download['id'] ); | |
} | |
} |
This file contains 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
<?php | |
/*** | |
edd_default_downloads_name | |
Change global Downloads name | |
***/ | |
add_filter('edd_default_downloads_name', 'drw_edd_global_labels'); | |
function drw_edd_global_labels($labels) { | |
$labels = array( | |
'singular' => __('Product','edd'), | |
'plural' => __('Products','edd') | |
); | |
return $labels; | |
} | |
//Update 'downloads' slug | |
define('EDD_SLUG', 'products'); |
This file contains 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
<?php | |
/*** | |
edd_insert_user | |
Remove new user notification emails in EDD | |
***/ | |
remove_action( 'edd_insert_user', 'edd_new_user_notification', 10, 2 ); |
This file contains 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
<?php | |
/*** | |
edd_payment_receipt_before | |
$payment obj Current EDD_payment object | |
Output content in template before receipt is rendered | |
***/ | |
add_action('edd_payment_receipt_before', 'drw_purchase_confirmation_text', 10, 2); | |
function drw_purchase_confirmation_text( $payment, $edd_receipt_args ) { | |
$payment = new EDD_Payment($payment->ID); | |
$downloads = $payment->downloads; | |
$gateway = $payment->gateway; //stripe //check | |
$gateway_text = ( 'stripe' == $gateway ) ? __('Credit Card', 'drw') : __('Check', 'drw'); | |
printf('<div class="message">%s %s</div>', __('You have paid by'), $gateway_text); | |
} | |
This file contains 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
<?php | |
/*** | |
edd_pre_add_to_cart | |
$download_id int Product being added | |
Fires before new item is added to cart | |
Example: Allow a product to be added only once to cart | |
***/ | |
add_action( 'edd_pre_add_to_cart', 'drw_edd_one_item_checkout', 10, 2 ); | |
function drw_edd_one_item_checkout( $download_id, $options ) { | |
if ( edd_item_in_cart($download_id) ) { | |
$cart_contents = edd_get_cart_contents(); | |
$cart_ids = array(); | |
foreach( $cart_contents as $item) { | |
$cart_ids[] = $item['id']; | |
} | |
$cart_key = array_search ($download_id, $cart_ids); | |
edd_remove_from_cart( $cart_key); | |
set_query_var( 'edd_duplicate', 'duplicate' ); | |
} | |
} | |
/*** | |
edd_before_checkout_cart | |
Hook to output content directly before cart is rendered | |
Example: Set warning for multiple products if duplicate is set | |
***/ | |
add_action( 'edd_before_checkout_cart', 'drw_edd_checkout_warnings' ); | |
function drw_edd_checkout_warnings() { | |
if ( get_query_var('edd_duplicate') ) { | |
printf('<div class="alert">%s</div>', __('This item can only be purchased once', 'drw')); | |
} | |
} |
This file contains 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
<?php | |
/*** | |
edd_recurring_update_subscription | |
$subscription_id int EDD_Subscription ID | |
Take action if Recurring Payments subscription status has changed | |
**/ | |
add_action( 'edd_recurring_update_subscription', 'drw_subscription_update_callback', 10, 1); | |
function drw_subscription_update_callback( $subscription_id = null ) { | |
if ( null == $subscription_id ) return; | |
$subscription = new EDD_Subscription( $subscription_id ); | |
$user_id = $subscription->customer->user_id; | |
//'pending', 'active', 'cancelled', 'expired', 'failing', 'completed' | |
$status = $subscription->get_status(); | |
if ( 'cancelled' || 'expired' == $status ) { | |
// make API call | |
} elseif( 'active' == $status ) { | |
// make API call | |
} | |
} |
This file contains 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
<?php | |
/*** | |
edd_update_payment_status | |
$payment_id int EDD_Payment object ID | |
$new_status str New payment status | |
$old_status str Old payment status | |
Take action after purchase status is changed - useful for check payments | |
***/ | |
add_action( 'edd_update_payment_status', 'drw_edd_after_check_purchase', 10, 3); | |
function drw_edd_after_check_purchase( $payment_id, $new_status, $old_status ) { | |
//bail if the order isn't approved | |
if ( !in_array($new_status, array('publish', 'complete')) ) { | |
return; | |
} | |
$payment = new EDD_Payment( $payment_id ); | |
$user_id = $payment->user_id; | |
//Do something with payment data | |
drw_update_data($user_id, $payment); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment