Search code examples
phpwordpresswoocommercepointsdiscount

WooCommerce Points and Rewards and discount rounds up


I am using WooCommerce Points and Rewards plugin. The issue I have is when applying points to cart, it is rounding up to the nearest integer. I would like for it to apply in cents.

For example: 10 points = 1 dollar. If customer has 11 points so the discount should be $1.10, but not $2.00. I've looked through the plugin code but do not see where this is being force to round up.

Any advise or thoughts?


Solution

  • This plugin round the points on the displayed cart notice… You can't apply in cents… You can only tune in the plugin settings the "Earn Points Rounding Mode" and the best round mode is: "Round to nearest integer"

    What you can do is to fix a minimal number of points to get the discount and display the related notice with the folowing code (Fixed to 100 points below):

    // Points and rewards conditional redeem points message display up to 100 points
    add_filter( 'wc_points_rewards_redeem_points_message', 'conditional_redeem_points_message', 10, 2 );
    function conditional_redeem_points_message( $message, $discount_available ){
        $points  = WC_Points_Rewards_Manager::calculate_points_for_discount( $discount_available );
        if( $points >= 100 ) 
            return $message;
        else
            return '';
    }
    

    And in the plugin settings you will Fix the same number for "Maximum Points Discount".

    So the notice will be displayed only for this minimal number of points and the available cart discount will be a real corresponding integer amount

    I haven't find already another way.