Skip to content

Instantly share code, notes, and snippets.

@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 October 13, 2025 19:59
Give points based on order total
<?php
add_filter('wpgens_loyalty_cart_points_before_discount', function($total_points, $cart) {
// Calculate the desired points based on actual paid amount
$cart_total = $cart->get_total('edit');
$cart_total_without_shipping = $cart_total - $cart->get_shipping_total() - $cart->get_shipping_tax();
// Award 2 points for every euro spent (excluding shipping)
$points_per_currency = 2;
$desired_points = floor($cart_total_without_shipping * $points_per_currency);
@goranefbl
goranefbl / functions.php
Created October 6, 2025 10:45
Hide points per role
<?php
/**
* Loyalty (WPGens) – gate features by ROLE instead of user meta.
* Default allowed roles: customer, subscriber.
* Change with: add_filter('wpgens_loyalty_allowed_roles', fn() => ['customer','vip']);
*/
/** Helper: does user have any of the allowed roles? */
function wpgl_user_has_allowed_role( $user_id ): bool {
if ( ! $user_id ) return false;
@goranefbl
goranefbl / functions.php
Last active October 6, 2025 10:43
GDPR Hide boxes
<?php
// Only allow users with specific meta field
add_filter('wpgens_loyalty_should_allow_points_for_user', function ($should_allow, $user_id, $source, $type, $points_delta) {
$is_gdpr_points_consent = get_user_meta($user_id, 'gdpr_points_consent', true);
return $is_gdpr_points_consent === 'yes';
}, 10, 5);
add_filter('wpgl_show_points_earning_box', function ($should_show) {
if (is_user_logged_in()) {
@goranefbl
goranefbl / points-page.php
Created September 17, 2025 12:20
GDPR Compliant template
<?php
/**
* Points Page Template
*/
if (!defined('ABSPATH')) {
exit;
}
@goranefbl
goranefbl / points-earn.php
Last active September 11, 2025 11:13
Newsletter override
<?php
/**
* Earn Points Template - Custom Override with Newsletter Signup
*/
if (!defined('ABSPATH')) {
exit;
}
@goranefbl
goranefbl / functions.php
Created September 11, 2025 11:07
points and rewards - limit to roles
add_filter('wpgens_loyalty_update_points', 'filter_points_by_user_role', 5, 6);
function filter_points_by_user_role($user_id, $points_delta, $type, $source, $reference_id = null, $description = null) {
// Define roles that should be excluded from points system
$excluded_roles = ['wholesale_customer', 'restricted_user', 'employee'];
// Get user object
$user = get_userdata($user_id);
if (!$user) {
return false; // User not found
<?php
/**
* Klaviyo Integration
*/
class WPGL_Klaviyo
{
private static $instance = null;
const INTEGRATION_KEY = 'klaviyo';
@goranefbl
goranefbl / class-wpgens-raf-checkout.php
Created August 21, 2025 22:59
class-wpgens-raf-checkout.php
<?php
/**
* Hook into checkout
*
* @since 2.0.0
*/
if (!defined('ABSPATH')) {
exit;
@goranefbl
goranefbl / functions.php
Created July 30, 2025 20:28
prevent coupons when points applied.
<?php
// Add this to your main plugin file or in a hooks class
add_filter('woocommerce_coupon_is_valid', 'prevent_coupons_when_points_applied', 10, 3);
function prevent_coupons_when_points_applied($is_valid, $coupon, $discount_object) {
// Skip validation for loyalty points coupons themselves
if (strpos($coupon->get_code(), 'loyalty_points_') === 0) {
return $is_valid;
}