Simple Points and Rewards

How can we help?

Search the documentation or ask the AI agent anything about the plugin.

PHP API: Custom Ways to Earn

Updated September 11, 2026

Register your own “ways to earn” entirely from code. You define the way once (points, frequency, caps, date window, roles, dashboard card) and award it by firing a trigger. Registered ways appear read-only in the Ways to Earn settings tab, where their rules are shown and their display order can be changed.

Register a way

Hook the spar_register_earn_ways action and call spar_register_custom_earn_way( array $args ) for each way. It returns true on success or false for invalid input.

ArgumentTypeDefaultDescription
idstring— (required)Your key: lowercase letters, digits, _ or -, max 64 chars. Must not collide with a built-in way.
namestring''Display name on the dashboard card.
descriptionstring''Short description under the name.
iconstring'fa-solid fa-star'Font Awesome class for the card icon.
pointsint0Points awarded each time the way is granted.
frequencystring'once'once, daily, weekly, monthly, or unlimited.
max_awardsint0Maximum total awards per user. 0 = unlimited.
start_datestring''Optional Y-m-d start of the eligibility window.
start_timestring''Optional 24h H:i, paired with start_date.
end_datestring''Optional Y-m-d end of the window.
end_timestring''Optional 24h H:i, paired with end_date.
rolesarrayarray()Role slugs allowed to earn. Empty = all roles.
enabledboolfalseSet true to make the way active.
show_on_dashboardboolfalseShow a card on the rewards dashboard.
show_countdownboolfalseLive “Ends in” countdown (needs an end date).
delayint0Wait this long before awarding (needs the Points Delay feature).
delay_unitstring'days'days or hours, paired with delay.
button_textstring''Card button label (button shows only with text + URL).
button_urlstring''URL the button links to.
button_idstring''Optional HTML id for the button.
button_classstring''Optional extra CSS class(es) for the button.

Reserved IDs (used by built-in ways, cannot be reused): signup, order, order_fixed, referral, first_order, nth_order, review, birthday, daily_login, spin_wheel, buy_products.

add_action( 'spar_register_earn_ways', function () {

    spar_register_custom_earn_way( array(
        'id'                => 'flash_bonus',
        'name'              => 'Weekend Flash Bonus',
        'description'       => 'Earn 100 bonus points this weekend only.',
        'icon'              => 'fa-solid fa-bolt',
        'points'            => 100,
        'frequency'         => 'once',       // once | daily | weekly | monthly | unlimited
        'max_awards'        => 0,            // 0 = unlimited total per user
        'start_date'        => '2026-01-10', // 'Y-m-d' (optional)
        'end_date'          => '2026-01-12',
        'roles'             => array(),      // empty = all roles
        'enabled'           => true,
        'show_on_dashboard' => true,
        'show_countdown'    => true,
        'button_text'       => 'Shop now',
        'button_url'        => 'https://example.com/shop',
    ) );

} );

Award a way

Once registered, award a way to a user with the trigger action. All configured rules (frequency, caps, date window, roles) are always enforced, so it is safe to call repeatedly — nothing happens when the user is not currently eligible.

// Fire the trigger (recommended)
do_action( 'spar_custom_earn_trigger', 'flash_bonus', 42 );

// Or call directly and check the result
$awarded = spar_award_custom_earn_way( 'flash_bonus', 42 ); // bool
Was this article helpful?