Skip to content

Instantly share code, notes, and snippets.

const wpgensUTMCookieManage = {
set: function (name, value, days) {
const expires = days ? new Date(Date.now() + days * 24 * 60 * 60 * 1000).toUTCString() : '';
const domain = this.getCleanHost(window.location.href) ? '; domain=' + this.getCleanHost(window.location.href) : '';
document.cookie = `${name}=${encodeURIComponent(value || '')}; expires=${expires}${domain}; path=/`;
},
get: function (name) {
const cookieArray = document.cookie.split(';');
for (let i = 0; i < cookieArray.length; i++) {
let cookie = cookieArray[i].trim();
@goranefbl
goranefbl / functions.php
Created June 3, 2024 18:39
Referral working with restricted coupons
<?php
add_filter('woocommerce_apply_with_individual_use_coupon', 'filter_apply_with_individual_use_coupon', 10, 4);
function filter_apply_with_individual_use_coupon($apply, $the_coupon, $applied_coupon, $applied_coupons) {
// Check if the coupon code starts with 'ref'
if (strpos($the_coupon->get_code(), 'ref') === 0) {
$apply = true;
}
return $apply;
}
@goranefbl
goranefbl / wpforms-track-referral.php
Last active May 9, 2024 09:52
Track referrals with WPForms
function wpgens_get_user_email_by_meta_or_email($meta_value) {
// Check if the meta_value is a valid email
if (is_email($meta_value)) {
return $meta_value; // If it's a valid email, return it directly
}
$args = array(
'meta_key' => 'gens_referral_id',
'meta_value' => $meta_value,
<?php
/******************************************************************************/
/******************************************************************************/
class CRBSWooCommerce
{
/**************************************************************************/
function __construct()
<?php
// Car rental plugin - booking form
add_action('woocommerce_new_order', 'wpgens_save_source_tracker_meta', 10, 1);
function save_source_tracker_meta($order_id)
{
if (!isset($_COOKIE['_wpgens_st_data'])) {
return;
}
@goranefbl
goranefbl / functions.php
Created March 18, 2024 09:56
biobalkan-customers
<?php
add_action( 'after_setup_theme', function() {
$current_user = wp_get_current_user();
/* is guest? */
if ( 0 == $current_user->ID ) {
return;
} else {
/* is not administrator */
<?php
/**
* Hook into checkout
*
* @since 2.0.0
*/
if (!defined('ABSPATH')) {
exit;
@goranefbl
goranefbl / class-wpgens-raf-checkout.php
Created January 15, 2024 22:06
allow emails in coupon fields
<?php
/**
* Hook into checkout
*
* @since 2.0.0
*/
if (!defined('ABSPATH')) {
exit;
<?php
/**
* Hook into checkout
*
* @since 2.0.0
*/
if (!defined('ABSPATH')) {
exit;
@goranefbl
goranefbl / class-wpgens-raf-order.php
Created January 14, 2024 23:11
Add coupon on first renewal.
<?php
/**
* Add Meta box to Order Screen
* @author WPGens
*/
if (!defined('ABSPATH')) {
exit;
}