The following snippet shows how to add a commission (percent) to the points awarded to the post author every time an user unlocks content through points.
function my_prefix_apply_commission_to_post_author_on_unlock( $post_id, $points, $points_type ) {
// Set the commission percent you want, as example, commission percent is set to 30%
// This means if post author got 10 points on unlock post then will lost 3, so the total earned will be 7
$commission_percent = 30;
$post_author = absint( get_post_field( 'post_author', $post_id ) );
if( $post_author === 0 ) return;
// Apply the commission to the points amount
$points = $points - ( $points * ( $commission_percent / 100 ) );
// Deduct points to post author
gamipress_deduct_points_to_user( $post_author, $points, $points_type );
}
// Required filter to apply commission on post unlock
function my_prefix_commission_on_unlock_post( $post_id, $user_id, $points, $points_type ) {
my_prefix_apply_commission_to_post_author_on_unlock( $post_id, $points, $points_type );
}
add_action( 'gamipress_restrict_content_post_unlocked_with_points', 'my_prefix_commission_on_unlock_post', 10, 4 );
// Required filter to apply commission on content unlock (through [gamipress_restrict_content] shortcode)
function my_prefix_commission_on_unlock_content( $content_id, $user_id, $post_id, $points, $points_type ) {
my_prefix_apply_commission_to_post_author_on_unlock( $post_id, $points, $points_type );
}
add_action( 'gamipress_restrict_content_content_unlocked_with_points', 'my_prefix_commission_on_unlock_content', 10, 5 );