Created
March 20, 2025 21:41
-
-
Save goranefbl/1c32ec1a1d1762d6dcb0c42839a82c41 to your computer and use it in GitHub Desktop.
WPGens Points and Rewards hooks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Add points | |
do_action( | |
'wpgens_loyalty_update_points', | |
$user_id, // User ID | |
$points_amount, // Points to add (positive) or remove (negative) | |
WPGL_Points_Activity_Type::EARN, // Activity type (EARN or DEDUCT) | |
WPGL_Points_Source_Type::PLACE_ORDER, // Source type (see below) | |
$reference_id = null, // Optional reference ID (e.g., order ID) | |
$description = null // Optional description | |
); | |
// Remove points | |
do_action( | |
'wpgens_loyalty_update_points', | |
$user_id, | |
-$points_amount, // Negative value to remove points | |
WPGL_Points_Activity_Type::DEDUCT, | |
WPGL_Points_Source_Type::ORDER_DISCOUNT, | |
$reference_id, | |
$description | |
); | |
Example usage: | |
*/ | |
// Add 100 points for a product review | |
do_action( | |
'wpgens_loyalty_update_points', | |
$user_id, | |
100, | |
WPGL_Points_Activity_Type::EARN, | |
WPGL_Points_Source_Type::PRODUCT_REVIEW, | |
$product_id, | |
'Product review for ' . $product_name | |
); | |
// Remove 50 points for a reward | |
do_action( | |
'wpgens_loyalty_update_points', | |
$user_id, | |
-50, | |
WPGL_Points_Activity_Type::DEDUCT, | |
WPGL_Points_Source_Type::REWARD_CLAIMED, | |
$reward_id, | |
'Redeemed reward: ' . $reward_name | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment