I used this link to set up a UserPoints Store: Drupal 7 - How to Set up a Simple UserPoints Store.

For some reason when I buy (flag) a node (store item) and for quantity I put more UserPoints, than the transaction is not blocked, which results in a negative user points balance.


  1. Either this issue is addressed and I set some wrong settings(I double checked everything so I don't think so)

  2. I need to make my own custom setting for the UserPoints not to enter negatives.

Is there a way I can set and pass a variable (enough_points=true) from (1st) rule "Check User Points" and then use it as a condition in (2nd) rule "Flag item"?

  • @NiallMurphy I would appreciate your thoughts on this.
    – Sammy7
    Aug 23, 2016 at 3:08

1 Answer 1


There is no Rules Condition related to the current total user points for a user. Except by using custom PHP code as in this example (which you could use in a Rules Conditionn Execute custom PHP code condition, e.g. to do some type of comparison):

global $user;
$current_points = userpoints_get_current_points($user->uid, 'all');
if ($current_points < 0) {return TRUE;}

However, there is a Rules Action "Load user points of a user", whereas you can ask for either a specific category, or for all categories together. This Rules Action provides a Rules variable (for which you can specify its name and description) which contains the amount of user points for the requested category. You can then use this variable in subsequent Rules Actions.

If you then want to use that variable within a Rules Condition, you have 2 ways of doing so:

  • Include the condition in a Rules Component, whereas you trigger the execution of that Rules Component via a Rules Action following the "Load user points of a user" (and passing the variable containing the amount of user points as a variable for the Rules Component).
  • Use the Conditional Rules module, so that you can specify Rules Conditions within Rules Actions.

Here is a basic example that displays a message about the current total user points for a user, after the user performed an update of some node (= the Rules Event, which you can change to any Rules event that you want):

{ "rules_display_userpoints_after_updating_content" : {
    "LABEL" : "Display userpoints after updating content",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "userpoints_rules", "rules" ],
    "ON" : { "node_update" : [] },
    "DO" : [
      { "userpoints_rules_get_current_points" : {
          "USING" : { "user" : [ "site:current-user" ], "tid" : "all" },
          "PROVIDE" : { "loaded_points" : { "total_points" : "Number of points in all categories together" } }
      { "drupal_message" : { "message" : "You now have [total-points:value] points" } }

Use the Rules UI to import the above rule in your own site if you want.

  • I'm a noobie to Drupal, you kind of confused me but answered my question. I realized I could just add the custom php script from rule "Check User Points" that checks the condition if the user has enough points. And add it as a condition to "Flag Item", basically they can never flag(buy) it if they don't have enough points!
    – Sammy7
    Aug 24, 2016 at 3:27
  • @Sammy7 Thanks for the comment (and accept). About using custom PHP script: that means PJP is stored in the database, which is perceived a practise you should try to avoid whenever possible.. Aug 24, 2016 at 4:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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