Skip to content

Instantly share code, notes, and snippets.

@goranefbl
goranefbl / functions.php
Last active March 1, 2026 06:42
Auto apply rank rewards
<?php
// 1. Auto 10% discount for users in a specific rank (e.g. Silver or higher)
add_action('woocommerce_cart_calculate_fees', function ($cart) {
if (is_admin() && !defined('DOING_AJAX')) return;
$user_id = get_current_user_id();
if (!$user_id || !class_exists('WPGL_Ranks_Core')) return;
$rank_slug_or_id = 'silver'; // slug or rank ID; true = this rank or higher
if (!WPGL_Ranks_Core::check_user_rank($user_id, $rank_slug_or_id, true)) return;
@goranefbl
goranefbl / functions.php
Created February 24, 2026 15:21
Lifetime discounts - loyalty plugin by wpgens for woocommerce
<?php
/**
* Diamond Rank — Automatic 15% lifetime discount, no points.
*
* 1. Applies a 15% cart discount on every order for Diamond rank users.
* 2. Disables points earning/redeeming for Diamond rank users (they get the
* flat discount instead).
*
* Requirements:
@goranefbl
goranefbl / functions.php
Created January 15, 2026 17:06
sync date on imported points
<?php
/**
* Sync import activity dates via admin URL
* Usage: /wp-admin/admin.php?wpgens_sync_import_dates=1&_wpnonce=NONCE
*
* Generate the link by visiting any admin page and copying the nonce from:
* /wp-admin/admin.php?wpgens_sync_import_dates=1&_wpnonce=<?php echo wp_create_nonce('wpgens_sync_import_dates'); ?>
*/
add_action('admin_init', function() {
@goranefbl
goranefbl / functions.php
Last active January 15, 2026 12:46
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, including tax)
*/
// For cart/checkout display
add_filter('wpgens_loyalty_cart_points_after_discount', function($total_points, $cart, $discount_ratio) {
// Subtotal + tax - discounts (including discount tax)
@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 February 12, 2026 10:23
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