1. Customize
  2. WooCommerce Integration
  3. Award points based on order’s total

Award points based on order’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 order’s total after complete the purchase.

Pay attention to the $ratio variable, that defines how much points will be awarded based on order’s total, for example, setting a ratio of 2, will award the 200% of the order’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_woocommerce( $order_id ) {
    $order = wc_get_order( $order_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( $order->user_id, absint( $order->get_total() * $ratio ), $points_type );
add_action( 'woocommerce_payment_complete', 'my_prefix_award_points_per_amount_spent_on_woocommerce' );

How can we help?