Skip to content

Instantly share code, notes, and snippets.

@goranefbl
goranefbl / functions.php
Created January 13, 2026 23:16
points calculation
<?php
/**
* Calculate points based on total amount instead of per-product
* Useful when plugins give some products for free
* 10 points per $1 spent (excluding shipping)
*/
// For cart/checkout display
add_filter('wpgens_loyalty_cart_points_after_discount', function($total_points, $cart, $discount_ratio) {
@goranefbl
goranefbl / functions.php
Created January 7, 2026 21:35
Limit maximum number of points discount
<?php
/**
* Limit TOTAL discount (coupons + points) to a maximum percentage
*
* This ensures customers can't stack coupon codes with points
* to get more than a specified total discount.
*/
add_filter('wpgens_loyalty_calculate_points_discount', function($discount_amount, $points, $conversion_rate) {
if (!function_exists('WC') || !WC()->cart) {
@goranefbl
goranefbl / functions.php
Created January 5, 2026 15:50
Redeem actions limit to certain ranks
add_filter('wpgens_loyalty_get_redeem_actions', 'restrict_redeem_actions_by_rank', 10, 2);
function restrict_redeem_actions_by_rank($redeem_actions, $user_id) {
if (!$user_id || !class_exists('WPGL_Ranks_Core')) {
return $redeem_actions;
}
// Define which rewards require which ranks
// Use the redeem action ID (visible in admin) and rank slug or ID
$rank_requirements = [
@goranefbl
goranefbl / functions.php
Created January 5, 2026 15:44
recalculate order points
/**
* Recalculate loyalty points when an order is updated in admin
*/
add_action('woocommerce_process_shop_order_meta', 'recalculate_loyalty_points_on_order_update', 50, 1);
function recalculate_loyalty_points_on_order_update($order_id) {
$order = wc_get_order($order_id);
if (!$order) {
return;
}
@goranefbl
goranefbl / functions.php
Created December 29, 2025 13:26
Check if customer bought product
/**
* Hide referral link/code if user hasn't purchased a specific product
*
* @param bool $hide Current hide status
* @param int $user_id Current user ID
* @return bool Whether to hide the referral link
*/
add_filter('gens_raf_hide_referral_link', function($hide, $user_id) {
// If already hidden, keep it hidden
if ($hide) {
@goranefbl
goranefbl / class-woocommerce-subscription.php
Last active January 6, 2026 09:01
Woo Subscription Integration with WPGens Loyalty Plugin
<?php
/**
* WooCommerce Subscription Integration for Points & Rewards
*
* Automatically applies available points as discount during subscription renewals
*
* @since 1.0.0
*/
class WPGL_WooCommerce_Subscription
2025-11-25T11:17:54+00:00 ERROR Array
(
[title] => ==== PERFORM REMOTE REQUEST ====
[message] => This is a performed remote request.
[data] => Array
(
[request] => Array
(
[endpoint] => https://e6e203eb98a4ca95-FamilleCarabelloBaumSAS-checkout-live.adyenpayments.proxypoc.woosa.com/checkout/v70/payments
[headers] => Array
<?php
/**
* WPGens RAF Events
* @author WPGens
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
@goranefbl
goranefbl / functions.php
Last active October 16, 2025 16:50
WooCommerce Points Plugin for WordPress multisite WPGens
<?php
/**
* Multisite Points Synchronization for WPGens Loyalty Program
* Keeps points synchronized across all sites in a multisite network
*/
class WPGL_Multisite_Points_Sync {
private static $syncing = false; // Prevent infinite loops
@goranefbl
goranefbl / functions.php
Last active December 3, 2025 11:43
Give points based on order total
<?php
add_filter('wpgens_loyalty_cart_points_after_discount', function($total_points, $cart, $discount_ratio) {
// Calculate points based on actual cart total
$cart_total = $cart->get_total('edit');
// Optional: Exclude shipping from points calculation
$cart_total_without_shipping = $cart_total - $cart->get_shipping_total() - $cart->get_shipping_tax();
// 1 point for every 10 dollars spent