I need something similar. I am using Gravity Forms for quiz system (not with the quiz add on). I am using a number field which calculates the total points. Labelling the field mycred_amount doesn’t work unless there is a fixed amount as the default value. It doesn’t recognise any calculated amount.
Gabriel, could your snippet be tweaked to apply to just one or a few Gravity Forms so we can leave the hook active also?
For anyone still looking to do this here is some code that worked for me. In this example it is form 2 and I am using a number field 5 and a single line text field in 11. The number field is a calculated filed. The single line text field just holds their user id.
This goes in your functions file:
add_action( 'gform_after_submission_2', 'add_points', 10, 2 );
function add_points( $entry, $form ) {
//getting points
$points_to_add = rgar( $entry, '5' );
// Set user I used a single line text in gravtiy forms and put {user:ID} in the default category. Then hid the field.
$user = rgar( $entry, '11' );
//default points
mycred_add( 'adding points', $user, $points_to_add, 'Points for being awesome!' );
//custom points. In this case I am using quiz_scored as the addition type as I have badges set up for this. You can use your own, or pick one already in use.
mycred_add( 'quiz_scored', $user, $points_to_add, 'Points for being awesome!', $ref_id, $ref_id, 'custom_point_type' );
}
This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.
Strictly Necessary Cookies
Strictly Necessary Cookie should be enabled at all times so that we can save your preferences for cookie settings.
If you disable this cookie, we will not be able to save your preferences. This means that every time you visit this website you will need to enable or disable cookies again.