Simple Points & Rewards supports a Benutzerdefiniert reward type that fires a WordPress action when claimed, allowing you to handle fulfillment in your own code. This is ideal for granting digital access, membership upgrades, store credit in another system, or any other action not covered by the built-in types.
Step 1 – Create the Custom Reward #
In Points & Rewards → Settings → Rewards, add a new reward and set Type to Benutzerdefiniert. Enter a Developer ID – this is a unique namespace string your code will use to identify the reward (e.g. my_plugin_vip_access).
Step 2 – Handle the Claim in PHP #
Hook into the spar_custom_reward_claimed action:
add_action( 'spar_custom_reward_claimed', 'handle_my_custom_reward', 10, 4 );
function handle_my_custom_reward( $user_id, $developer_id, $reward, $cost_points ) {
if ( 'my_plugin_vip_access' !== $developer_id ) {
return; // Not our reward
}
// Example: grant a custom capability
$user = new WP_User( $user_id );
$user->add_cap( 'vip_member' );
// Example: set a user meta flag
update_user_meta( $user_id, '_my_plugin_vip_active', 1 );
// Example: log to a third-party system
my_crm_api_grant_reward( $user_id, $reward['name'] );
}
Step 3 – Veto Eligibility (Optional) #
If your custom reward should only be claimable under certain conditions, use the spar_can_redeem_reward filter:
add_filter( 'spar_can_redeem_reward', 'check_my_reward_eligibility', 10, 3 );
function check_my_reward_eligibility( $can_redeem, $user_id, $reward ) {
if ( isset( $reward['developer_id'] ) && 'my_plugin_vip_access' === $reward['developer_id'] ) {
// Only allow if customer has made at least 5 orders
$order_count = wc_get_customer_order_count( $user_id );
if ( $order_count < 5 ) {
return false;
}
}
return $can_redeem;
}
Points Cost Override #
You can dynamically adjust the points cost of any reward (including custom ones) using the spar_belohnung_kosten_punkte filter:
add_filter( 'spar_reward_cost_points', 'dynamic_reward_cost', 10, 3 );
function dynamic_reward_cost( $cost, $reward, $user_id ) {
// VIP users get a 50% discount on reward costs
if ( user_has_cap( $user_id, 'vip_member' ) ) {
return round( $cost * 0.5 );
}
return $cost;
}