Skip to content

Instantly share code, notes, and snippets.

@goranefbl
goranefbl / functions.php
Created August 16, 2024 12:30
Funnelkit Automation Referral Tag
<?php
if (!bwfan_is_autonami_pro_active() || version_compare(BWFAN_PRO_VERSION, '2.0.3', '>=')) {
class BWFAN_Contact_Referral_ID extends BWFAN_Merge_Tag {
private static $instance = null;
public function __construct() {
$this->tag_name = 'contact_referral_id';
$this->tag_description = __('Contact Referral ID', 'wp-marketing-automations');
@goranefbl
goranefbl / functions.php
Created August 13, 2024 08:47
Generate coupon once
<?php
add_action('init', 'generate_coupon_manually');
function generate_coupon_manually() {
if (isset($_GET['generate_once']) && $_GET['generate_once'] == 'true') {
// Check if admin
if (!current_user_can('manage_options')) {
wp_die('You do not have permission to access this page.');
}
<?php
add_action('wpgens_raf_new_user_referral_id', 'process_new_user_referral', 10, 2);
function process_new_user_referral($referral_id, $user_id) {
// Get user data
$user = get_userdata($user_id);
$email = $user->user_email;
// Send to Klaviyo
@goranefbl
goranefbl / functions.php
Created August 6, 2024 10:18
Perbello auto apply coupons
<?php if (!defined('ABSPATH')) exit; // Exit if accessed directly
/**
* @param $order_get_id
* hook to thank you page referer plugin
* @@@ codja
*/
function cj_action_woocommerce_thankyou($order_get_id)
{
if (class_exists('WPGens_RAF')) {
<?php
/**
* Hook into checkout
*
* @since 2.0.0
*/
if (!defined('ABSPATH')) {
exit;
<?php
add_action('woocommerce_before_checkout_form', 'check_gens_raf_cookie_and_display_message', 10);
function check_gens_raf_cookie_and_display_message() {
if (isset($_COOKIE['gens_raf'])) {
wc_print_notice('Thank you for using a referral link! Your discount will be applied at checkout.', 'success');
}
}
@goranefbl
goranefbl / functions.php
Created July 14, 2024 21:07
webcare plugin
<?php
function user_has_activation_key($user_id) {
global $wpdb;
$user = $wpdb->get_row($wpdb->prepare(
"SELECT user_activation_key FROM {$wpdb->users} WHERE ID = %d",
$user_id
));
@goranefbl
goranefbl / functions.php
Last active July 3, 2024 09:02
Change referral shortcode
<?php
function override_woo_gens_raf_advance_shortcode() {
remove_shortcode('WOO_GENS_RAF_ADVANCE');
add_shortcode('WOO_GENS_RAF_ADVANCE', 'custom_woo_gens_raf_advance_shortcode');
}
add_action('init', 'override_woo_gens_raf_advance_shortcode');
function custom_woo_gens_raf_advance_shortcode($atts) {
@goranefbl
goranefbl / functions.php
Created June 24, 2024 11:35
Enable referral link for specific user roles, disable for users without 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_orders($current_user->ID) && !in_array('editor', $current_user->roles)) {
return 'Referral code is available only to users with orders or Editors';
}
return $raf_code;
<?php
// Function to get the referrer user ID
function get_referrer_user_id($rafID) {
// Check if the referrer is a guest using email
if (filter_var($rafID, FILTER_VALIDATE_EMAIL)) {
return $rafID;
}
// Retrieve the referrer user ID based on the custom meta field 'gens_referral_id'
$gens_users = get_users(array(