Skip to content

Instantly share code, notes, and snippets.

@goranefbl
goranefbl / wpgens-points-max-order-percent.php
Created November 12, 2026 10:33
WPGens Points and Rewards / Loyalty Program: limit points redemption to 30% of the order
<?php
/**
* Points and Rewards / Loyalty Program: let customers pay at most 30% of an order with points.
*
* The 30% is taken from the products in the cart after other coupons, including tax,
* without shipping. It lowers the "Maximum points" setting for each cart, so checkout
* shows the right maximum and never deducts more points than the discount it gives.
* Keep the built-in "Maximum points" setting high so it doesn't cut in first.
*/
@goranefbl
goranefbl / wpgens-points-from-eligible-total.php
Created October 20, 2026 22:01
WPGens Points and Rewards: earn points on the total of eligible products (respects Disable Points, rounds once per order)
<?php
/**
* WPGens Points and Rewards: calculate earned points from the total of eligible products.
*
* - Only products that earn points count. Products with "Disable Points" (or excluded
* by other plugin settings, such as "Exclude Sale Products") are left out.
* - The eligible amount includes VAT and discounts, and excludes shipping.
* - The earning rate from the plugin settings (for example 1 point per 20) is applied
* to the whole eligible amount and rounded up once, not per product unit.
* - The cart/checkout message and the product page message use the same calculation.
@goranefbl
goranefbl / wpgens-points-from-order-total.php
Created October 17, 2026 09:08
WPGens Points and Rewards: calculate earned points from the order total (1 point per 20, rounded up)
<?php
/**
* WPGens Points and Rewards: calculate earned points from the order total.
*
* Awards 1 point for every 20 (store currency) of the order total, rounded up.
* The amount includes VAT and discounts and excludes shipping.
*
* Add to your theme's functions.php or a code snippets plugin.
* If you change the earning rate in the plugin settings, update the 20 below as well.
*
@goranefbl
goranefbl / woocommerce-apply-coupon-from-url.php
Created October 14, 2026 15:44
WooCommerce: apply a coupon from a URL parameter (e.g. Klaviyo email links)
<?php
/**
* Apply a WooCommerce coupon from a URL parameter.
*
* Usage: link to any page with ?coupon=CODE, for example in a Klaviyo email:
* https://yourstore.com/product-category/shoes/?coupon={{ person.dck_woo_coupon }}
*
* The coupon is saved to the customer's session and applied automatically
* as soon as the cart contains a product the coupon is valid for.
*
@goranefbl
goranefbl / raf-exclude-gift-voucher.php
Created October 1, 2026 05:33
Refer a Friend Premium: exclude gift voucher orders from triggering referral rewards
<?php
/**
* Refer a Friend Premium (WPGens) - don't reward referrals when the order contains a gift voucher.
*
* If a referred customer's order contains any of the listed products, the advocate
* (and the friend) won't get a referral coupon and the referral won't be counted.
* The reason is shown in the referral info box on the order screen.
*
* Add to your child theme's functions.php or via the Code Snippets plugin.
*/
@goranefbl
goranefbl / functions.php
Created August 13, 2026 11:42
cap referrals per rank
<?php
/**
* Example: Per-rank yearly cap on referral email invitations
*
* Each VIP rank is allowed to send a different number of referral email
* invitations per calendar year. Once a customer reaches their rank's limit,
* the "invite friends by email" action is rejected with a friendly message
* until January 1, when the counter resets automatically.
*
* Example caps used below: Bronze 3, Silver 5, Gold 10, Platinum 15.
@goranefbl
goranefbl / functions.php
Created May 19, 2026 22:06
Translatepress support for Loyalty Widget
<?php
/**
* WPGens Loyalty: hardcoded TranslatePress fallback (ID-based).
*/
// ID-based action translations — id matches the row in the loyalty admin
// (Earning Actions list). Update as needed.
function wpgl_tp_id_map() {
return [
# AI Knowledge Assistant – Product + Documents RAG Platform
## Purpose
Build a multi-tenant AI knowledge assistant that can:
- answer questions using organization-specific content
- use both structured product content and uploaded PDFs
- ingest website content from WordPress via REST API
- keep content fresh via sync jobs and webhooks
@goranefbl
goranefbl / functions.php
Created March 18, 2026 14:47
snippet to run on past orders
<?php
/**
* Recalculate points for orders between Jan-Dec 2025 after BGN→EUR currency change.
* Run once via snippets plugin, then disable/delete.
*
* IMPORTANT: First adjust order totals from BGN to EUR, then run this snippet.
*/
add_action('init', function () {
// Safety: only run for admins
if (!current_user_can('manage_options')) return;
@goranefbl
goranefbl / functions.php
Created March 13, 2026 13:30
Auto apply coupon codes to renewals - loyalty plugin
<?php
/**
* Auto-apply loyalty coupons on WooCommerce Subscription renewals
*
* When a subscription renewal order is created, this snippet checks if the user
* has any unused loyalty coupons (matching the configured coupon prefix) and
* applies them as a discount fee on the renewal order.
*
* Works with both WooCommerce Subscriptions (official) and ThemeHigh Subscriptions.