Skip to content

Instantly share code, notes, and snippets.

@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);
@goranefbl
goranefbl / hs-widget.php
Created February 13, 2025 12:37
hs-widget.php
<?php
/* @var $args array */
$tracking_actions = false;
if ( class_exists('WC_Shipment_Tracking_Actions') ) {
$tracking_actions = new \WC_Shipment_Tracking_Actions();
}
if ( ! class_exists( 'TomShippingBob' ) ) {
include_once "../inc/classes/TomShippingBob.class.php";
}
@goranefbl
goranefbl / functions.php
Created January 24, 2025 19:43
different amount per product
<?php
add_filter('gens_raf_coupon_amount', 'modify_raf_coupon_amount', 10, 2);
function modify_raf_coupon_amount($amount, $order_id) {
// Get the order object
$order = wc_get_order($order_id);
if (!$order) {
return $amount; // Return default amount if order not found
@goranefbl
goranefbl / functions.php
Created January 16, 2025 09:27
utm-add-on-hold-status
<?php
namespace WPGens_ST\Includes\WooCommerce;
use Automattic\WooCommerce\Utilities\OrderUtil;
defined('ABSPATH') || exit;
class WPGENS_ST_Orders_Analytics
{
@goranefbl
goranefbl / functions.php
Last active January 15, 2025 23:13
partial use of coupons
<?php
add_action('woocommerce_checkout_order_processed', 'handle_partial_coupon_usage', 10, 3);
function handle_partial_coupon_usage($order_id, $posted_data, $order) {
$applied_coupons = $order->get_coupon_codes();
// Ensure only one coupon is applied
if (count($applied_coupons) === 1) {
$coupon_code = current($applied_coupons);
$coupon = new WC_Coupon($coupon_code);
@goranefbl
goranefbl / index.js
Last active December 23, 2024 12:22
goran-perbelle
import Fastify from "fastify";
import WebSocket from "ws";
import fs from "fs";
import dotenv from "dotenv";
import fastifyFormBody from "@fastify/formbody";
import fastifyWs from "@fastify/websocket";
// Load environment variables from .env file
dotenv.config();
// Retrieve the OpenAI API key from environment variables. You must have OpenAI Realtime API access.
const { OPENAI_API_KEY } = process.env;
@goranefbl
goranefbl / functions.php
Created December 8, 2024 13:09
UTM Friends Email notification
<?php
add_action('woocommerce_checkout_order_processed', 'send_custom_order_email', 10, 1);
function send_custom_order_email($order_id) {
$order = wc_get_order($order_id);
$utm_source = get_post_meta($order_id, '_wpg_first_source', true);
// Only send email if utm_source exists and is an email address
if (!empty($utm_source) && filter_var($utm_source, FILTER_VALIDATE_EMAIL)) {