I trying to do something for every purchase of corresponding product in easy digital download. Let say i need to add the auto random discount code for every purchase made in easy digital download. I tried with different hooks. But still i didn't get the correct callback on success process of paypal. Let i make it alert on success callback of paypal.

what i am trying is something like this

if($paypal == 'success') {
//do something
} else {
//do something
function pw_edd_on_complete_purchase($payment_id) {

    // Basic payment meta
    $payment_meta = edd_get_payment_meta($payment_id);
    <script type="text/javascript">
        alert("this is for payment");

    // Cart details
    //$cart_items = edd_get_payment_meta_cart_details($payment_id);

    // do something with payment data here

add_action('edd_complete_purchase', 'pw_edd_on_complete_purchase');

But i am not sure how to do this. I have the product which name as gift card let say $5. If the user purchased this gift card then he/she get the random code of discount for purchasing some other product in future. Can anyone tell me which hook is achieving the above criteria ?

Any Suggestion would be great thanks


You should be able to generate discount codes within your callback function by using the edd_add_discount() function. You can learn more about this function here on the EDD Codex to see what specific data you need to pass to the function.

However, edd_complete_purchase might not be the right action to hook to. If you only want specific codes to be generated when specific payment types (PayPal) are successfully charged, you might want to instead hook to edd_before_payment_status_change. This is called in edd_update_payment_status(), which you can also see on the EDD Codex here, and should let you only run edd_add_discount() if the $new_status within edd_update_payment_status() is 'published' (or otherwise for a successful payment, instead of 'failed' or 'pending').

  • 1
    If you want to use the edd_complete_purchase hook, you could check the gateway that was used by pulling it from the payment meta so that your action only fires for PayPal payments. – Pippin Oct 28 '13 at 22:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.