1. Filter for Publishing a Post
Default: 20 EXP + 5 Coin when a user publishes a post for the first time. Example customization:
add_filter( 'init_plugin_suite_user_engine_publish_post_rewards', function( $rewards, $post ) {
$rewards['exp'] = 50;
$rewards['coin'] = 10;
return $rewards;
}, 10, 2 );
2. Filter for User Registration
Default: 50 EXP + 20 Coin when a new user registers. Example customization:
add_filter( 'init_plugin_suite_user_engine_user_register_rewards', function( $rewards, $user_id ) {
$rewards['exp'] = 100;
$rewards['coin'] = 50;
return $rewards;
}, 10, 2 );
3. Filter for Profile Update
Default: 30 EXP + 10 Coin when a user completes their profile for the first time. Example customization:
add_filter( 'init_plugin_suite_user_engine_update_profile_rewards', function( $rewards, $user_id, $old_user_data ) {
$rewards['exp'] = 60;
$rewards['coin'] = 20;
return $rewards;
}, 10, 3 );
4. Filter for Daily Login
Default: 10 EXP + 5 Coin for the first login of the day. Example customization:
add_filter( 'init_plugin_suite_user_engine_daily_login_rewards', function( $rewards, $user_id, $today ) {
$rewards['exp'] = 25;
$rewards['coin'] = 15;
return $rewards;
}, 10, 3 );
5. Filter for WooCommerce Order Completion
Default: rewards are calculated based on the order total (10,000 VND = 1 Coin, 5,000 VND = 1 EXP, with a minimum of 1 Coin and 5 EXP). Example override:
add_filter( 'init_plugin_suite_user_engine_woo_order_rewards', function( $rewards, $user_id, $order, $total ) {
return [
'exp' => 200,
'coin' => 100,
];
}, 10, 4 );
Alternative Example: Custom WooCommerce Rewards in USD
By default, the plugin calculates rewards in VND. If your store uses USD, you can set your own rule, for example: $1 = 1 Coin and $1 = 2 EXP (with minimum 1 Coin, 5 EXP):
add_filter( 'init_plugin_suite_user_engine_woo_order_rewards', function( $rewards, $user_id, $order, $total ) {
if ( $order instanceof WC_Order && strtoupper( $order->get_currency() ) === 'USD' ) {
$total_usd = (float) $total;
$coin = max( 1, (int) floor( $total_usd * 1 ) );
$exp = max( 5, (int) floor( $total_usd * 2 ) );
$rewards = [
'exp' => $exp,
'coin' => $coin,
];
}
return $rewards;
}, 10, 4 );
Tip: For dynamic exchange rates, fetch the rate from plugin settings or an API and multiply it with $total_usd before calculating EXP and Coin.
Conclusion
The new filters in Init User Engine 1.2.3 make customizing EXP and Coin rewards simple and flexible, while maintaining full backward compatibility. Developers can safely manage rewards through filters instead of editing core code, ensuring seamless plugin updates.
Comments