1. Customize
  2. Easy Digital Downloads Integration
  3. Award points based on payment’s total

Award points based on payment’s total

Note: We have released the Points Per Purchase Total add-on that includes this functionality.
You can find more information in the add-on page.

The following snippet shows how to award points to the user based on payment’s total after complete the purchase.

Pay attention to the $ratio variable, that defines how much points will be awarded based on payment’s total, for example, setting a ratio of 2, will award the 200% of the payment’s total as points and if you set it to 0.2 then will award the 20%.

function my_prefix_award_points_per_amount_spent_on_edd( $payment_id ) {

    $payment = new EDD_Payment( $payment_id );

    // The ratio value used to convert the amount spent into points
    // Setting it to 1 will award the same points as amount spent ($40 = 40 points)
    // Setting it to 2 will award the double of points of amount spent ($40 = 80 points)
    // Setting it to 0.5 will award the half of points of amount spent ($40 = 20 points)
    $ratio = 1;

    // The points type slug you want to convert the amount
    $points_type = 'points-type-slug';

    // Award the points to the user
    gamipress_award_points_to_user( $payment->user_id, absint( $payment->total * $ratio ), $points_type );

}
add_action( 'edd_complete_purchase', 'my_prefix_award_points_per_amount_spent_on_edd' );

How can we help?