Replying to Avatar Dune Messias

Well according to Chat (again) this is a known issue: plugins like WooRewards don’t run on the first visit via a referral URL — the plugin’s code doesn’t execute until a second visit, which suggests something is bypassing WordPress early on.

From reddit: “It usually comes down to caching and when WooCommerce sessions actually start. What helped me was hooking into WordPress really early, like on init or wp_loaded, to catch the referral info before any caching or redirects happen."

Immediate Fixes to Try

1. Ensure Cloudflare Excludes Referral URLs from Cache

Cloudflare’s default behavior often serves cached pages for URLs with query parameters unless explicitly configured otherwise. You can address this by:

• Using Cache Rules to bypass caching when the query string contains your referral parameter. Example rule: (If http.request.uri.query contains "ref", then bypass cache.)

2. Use Cloudflare Transform Rules for Query Ignoring

If you’re using “Cache Everything,” query strings may still get cached. Transform Rules can help you ignore specific query parameters — like ref — to ensure each visit is treated as unique

3. Launch Referral Logic at the Earliest Hooks

Move your referral tracking code to the earliest stages of WordPress execution — ideally in an mu‑plugin — using hooks like:

add_action('init', 'set_referral_cookie', 1);

function set_referral_cookie(){

if (isset($_GET['ref'])) {

setcookie('custom_ref', sanitize_text_field($_GET['ref']), time() + DAY_IN_SECONDS * 30, '/');

error_log('Referral cookie set: ' . $_GET['ref']);

}

}

If you don’t see this log on first visit — but do on reload — it’s strong evidence that the code isn’t being run due to caching interference.

4. Add Debug Logs for Plugin Calls

Add logging at the very start of your referral plugin’s main file or in a mu-plugin:

error_log('Referral plugin reached init at ' . current_time('mysql'));

If you don’t see this log on first visit — but do on reload — it’s strong evidence that the code isn’t being run due to caching interference.

Summary Diagnostic Flow

Step

Description

1. Add early logging

Confirm if plugin or cookie logic executes at first visit.

2. Test referral link

Use curl -I https://satosh.ee/?ref=test — check headers like cf-cache-status: HIT vs MISS.

3. Adjust cache rules

Use Cloudflare Cache or Transform rules to bypass referrals.

4. Validate in Incognito

Remove preload/prefetch interference from browser.

5. Re-test every change

Confirm if the plugin logic actually runs on first visit post-changes.

Hey, just wanted to say thanks for the input, I've tried most of the things on your list beforehand, and as much as I've continued testing the culprit seems to be: referral cookie attempts to set too late, after WooCommerce sessions have started or headers have been sent. On first visit, no session exists → cookie cannot be set → referral only works on second visit.

I've tried to do step 3: Launch Referral Logic at the Earliest Hooks many times (even before posting this problem here) with different code snippets from ChatGPT, Claude, now also Lumo and Duck.ai (which, admittedly, also uses ChatGPT) but none of the solutions work. The end result is still the same (or sometimes worse).

Reply to this note

Please Login to reply.

Discussion

Bummer. Maybe completely disabling Cloudflare?

Rocket.net support said they can't even completely disable it 🤦‍♂️ Only specific URL paths