Skip to content

Instantly share code, notes, and snippets.

@goranefbl
goranefbl / functions.php
Created April 5, 2025 06:23
refer a friend hook
<?php
/**
* Refer a Friend integration with points
*/
class WPGL_Refer_A_Friend
{
private static $instance = null;
public static function init()
@goranefbl
goranefbl / readme.txt
Created April 3, 2025 10:25
wpgens points and rewards api
**Custom Point Actions & Integrations**
You can add custom point actions by using the `wpgens_loyalty_update_points` action. Here are some examples:
```php
// Award points for a custom action
function award_custom_points($user_id, $points, $description) {
do_action(
'wpgens_loyalty_update_points',
@goranefbl
goranefbl / functions.php
Last active March 30, 2025 06:06
WPGens Points and Rewards - manual refund points per order
<?php
// Add meta box to order page
add_action('add_meta_boxes', 'add_points_refund_box');
function add_points_refund_box() {
if (class_exists('Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController')) {
$controller = wc_get_container()->get('Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController');
$screen = $controller->custom_orders_table_usage_is_enabled()
? wc_get_page_screen_id('shop-order')
: 'shop_order';
@goranefbl
goranefbl / functions.php
Created March 25, 2025 10:54
wpgens auto apply coupon when product is added to cart
<?php
add_action( 'woocommerce_add_to_cart', 'wpgens_auto_apply_coupons_on_add_to_cart', 10, 6 );
function wpgens_auto_apply_coupons_on_add_to_cart( $cart_item_key, $product_id, $quantity, $variation_id, $variation, $cart_item_data ) {
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;
if ( ! is_user_logged_in() )
return;
@goranefbl
goranefbl / functions.php
Created March 20, 2025 21:41
WPGens Points and Rewards hooks
<?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)
@goranefbl
goranefbl / email-body-coupon.php
Last active March 14, 2025 21:13
coupon email translatable
<?php
/**
* Email Body
*
* @see https://wpgens.com/docs/how-to-edit-template-files-and-keep-them-after-plugin-update/
* @version 2.0.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
@goranefbl
goranefbl / email-body-share.php
Last active March 13, 2025 14:16
hardoded sharing email
<?php
/**
* Email Body for Email Share
*
* @see https://wpgens.com/docs/how-to-edit-template-files-and-keep-them-after-plugin-update/
* @version 2.0.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
@goranefbl
goranefbl / functions.php
Created February 26, 2025 11:57
WPGENS RAF: hide referral link for users without referral orders
<?php
add_filter('wpgens_raf_code', 'gens_raf_code', 10, 1);
function gens_raf_code($raf_code) {
$current_user = wp_get_current_user();
if (!user_has_friends($current_user->ID)) {
return 'Referral code is available only to users with friends';
}
return $raf_code;
@goranefbl
goranefbl / functions.php
Last active February 26, 2025 11:02
Hide referral link for users that spent below 300
<?php
add_filter('wpgens_raf_code', 'gens_raf_code', 10, 1);
function gens_raf_code($raf_code) {
$current_user = wp_get_current_user();
$total_spent = get_user_total_spent($current_user->ID);
if ($total_spent < 300) {
return 'Referral code is available only to users who have spent at least 300';
}
@goranefbl
goranefbl / functions.php
Last active February 18, 2025 06:53
Add product variations
<?php
add_action('gens_after_generate_user_coupon', 'add_product_ids_to_raf_coupon', 10, 4);
function add_product_ids_to_raf_coupon($user_id, $type, $order, $coupon_id) {
// Logic to determine which variation IDs to add
$variation_ids = array(123, 456, 789); // Replace with your actual variation IDs
// Get existing product IDs
$existing_ids = get_post_meta($coupon_id, 'product_ids', true);