Closed JDGrimes closed 7 years ago
We didn't end up addressing this in the points reactor of the new hooks API, though it is a feature that we would still like to pursue.
At this point, dynamic awards are a feature that we know that we definitely want. The only question here is how to best handle them. The idea of just supplying a number value anyway, but having the description be "For every $10 of a purchase" is actually pretty clever. However, now that we let users set the description to whatever they want, I question its feasibility.
Possibly we should approach this from a completely different direction. Maybe we should just get rid of the points column entirely, and combine that information into the general description. The downside there of course is that it would no longer be possible for a user to sort the list by the number of points. Actually, we would still have that information to use internally, or using a hidden column or something. So it would still be possible to allow sorting like that.
I think though, that the best way forward is probably to just allow for a description of how the points are calculated to be supplied instead of a points value. This is what we originally suggested, although now we are talking about the new hooks API instead of the old points hooks, but I think it could still be done. The question is just how best to do it. I had thought of using a filter, and that would work, but it just doesn't seem ideal.
The How to Get Points shortcode displays a table of actions which award points and how many points is awarded for each. This was created to work with hooks that have a
points
field that specifies the number of points to award for the action. That default behavior can be overridden for each hook type by declaring a customget_points()
method. However, that method is still expected to return an integer value.Consider a case in which a hook awards points based on another value—the order total at checkout, for example. This hook has a dynamic award value. In such a case, an integer value in the points column of the How to Get Points table doesn't make sense.
Say you have a hook that awards a user points amounting to 10% of any purchase they make. You might want to put "N/A" or "dynamic" or something like that in the points column. However, even if you declare a
get_points()
method in your hook and have it return that string, your hook wont be shown in the table because it wont be recognized as a valid points value bywordpoints_format_points()
.A current workaround would to have the
get_points()
method return 1, and havegenerate_description()
return "For every $10 of a purchase."This first thing that we need to do is answer the general question of how dynamic hooks are to be handled. Is this something that we want to promote and support? Or should they be refactored so that they aren't dynamic. We'll need to consider any other possible implications of dynamic hooks as well.
If we do give the go-ahead to supporting dynamic hooks, then we need to answer the question of how best to handle this, in this shortcode and possibly elsewhere.