pull down to refresh
Thank you for the detailed & step-by-step response! Phase 1 I have tried, although I will make a note to the plugin devs that it would be good to have an option to have specific referral links i.e. site.com/ref/code. Currently the Referral Codes plugin creates them simply as site.com/code which is the same format as any other page. However, I did have Rocket.net support turn off Cloudflare for the specific URL's and it didn't work, so that's probably not the issue anyway. Phase 2 & 3 I have also tried in different formats (and solutions via different LLM's - I'm not a dev myself, unfortunately), but I'll definitely give your specific instructions a go.
One thing that I didn't mention - ChatGPT said it shouldn't make a difference in how the links act - was that there was also a PHP error that came up in debugging:
PHP Deprecated: Creation of dynamic property WC_Coupon::$lws_referralcode
Chat: Not critical for functionality yet, but in PHP 8.2+ dynamically adding properties to objects is deprecated. The plugin is trying to attach $lws_referralcode directly to the WC_Coupon object. This should ideally be stored in meta instead:
php
Copy code
$coupon->update_meta_data('lws_referralcode', $code);
Chat: This doesn’t directly break the cookie behavior, but it’s good to fix for future PHP compatibility.
In any case, I'll follow your instructions and see where it takes me. Can't guarantee I'll get to it tonight (has been a long day), but tomorrow at the latest!
It worked?
No :/ I did use ChatGPT again in order to do some of the things like the MU plugin, but nothing seems to do the trick
The problem occurs when referral plugin code doesn't execute on first page load due to caching, server-level redirects, or WordPress initialization timing issues.
Step by Step solutionStep by Step solution
Phase 1: Quick Wins (Start Here - 70% Success Rate)Phase 1: Quick Wins (Start Here - 70% Success Rate)
Step 1: Test in Incognito Mode
Step 2: Disable All Caching
For Cloudflare users:
yoursite.com/*ref*→ Cache Level: BypassFor WordPress caching plugins:
Phase 2: Server-Level Issues (25% Success Rate)Phase 2: Server-Level Issues (25% Success Rate)
Step 3: Check .htaccess File
.htaccessto.htaccess-backupFix .htaccess redirect order:
# Custom redirects MUST come BEFORE WordPress section RewriteCond %{QUERY_STRING} ^(.*)ref=(.*)$ [NC] RewriteRule ^(.*)$ /$1?%1ref=%2 [L] # BEGIN WordPress <IfModule mod_rewrite.c> # WordPress rules here </IfModule> # END WordPressPhase 3: WordPress Code Solutions (30% Success Rate)Phase 3: WordPress Code Solutions (30% Success Rate)
Step 4: Force Early Plugin Execution
Add this code to your theme's
functions.phpfile:// Force early referral tracking function force_early_referral_tracking() { if (isset($_GET['ref']) || isset($_GET['referral']) || isset($_GET['affiliate'])) { // Force WooCommerce session start if (class_exists('WooCommerce')) { WC()->session->init(); } // Force session start if (!session_id()) { session_start(); } } } add_action('init', 'force_early_referral_tracking', 1);Step 5: Server-Level Cache Bypass
Add before WordPress rules in
.htaccess:# Bypass caching for referral URLs <IfModule mod_rewrite.c> RewriteCond %{QUERY_STRING} (ref=|referral=|affiliate=) [NC] RewriteRule .* - [E=no-cache:1] Header set Cache-Control "no-cache, no-store, must-revalidate" env=no-cache </IfModule>Note Hosting-Specific Quick FixesNote Hosting-Specific Quick Fixes
The success rate varies significantly by hosting environment. Cloudflare users should start with CDN configuration, while shared hosting users often need to address server-level restrictions.
Why This Happens??
This issue occurs because
Advanced Solutions (If above Steps Fail)Advanced Solutions (If above Steps Fail)
Create Must-Use Plugin:
/wp-content/mu-plugins/force-referral-early.php:<?php function force_referral_plugins_early() { if (isset($_GET['ref']) || isset($_GET['referral'])) { while (ob_get_level()) { ob_end_clean(); } if (!headers_sent()) { header('Cache-Control: no-cache'); } } } add_action('muplugins_loaded', 'force_referral_plugins_early', 1);To make sure this never happens againTo make sure this never happens again
The key insight is that "something else takes charge before WordPress" meaning the issue occurs at the server/CDN level before your WordPress plugins can execute. Start with the highest success rate solutions first, and work systematically through the troubleshooting matrix.