Meta for WooCommerce sets _fbp from PHP, so new visitors can’t fill your page cache
Black Friday is on 27 November, and if you’re paying for Meta or Google ads that week, the page each click lands on is the one you most want served from your page cache. If your store runs Meta for WooCommerce with a pixel connected, it’s also the page least likely to be in it.
Only visitors who already have Meta’s _fbp cookie can put pages into your page cache. Anyone else who requests an uncached page gets that cookie set by PHP, and a page cache won’t store a response that sets a cookie. New visitors from an ad don’t have the cookie yet.
I checked this against Meta for WooCommerce 3.7.8, the latest version on wordpress.org and GitHub as of 11 November 2026, and the server-side cookie code is still on the plugin’s main branch on GitHub. wordpress.org lists the plugin at 400,000+ active installs.
The problem
What happens to each kind of request:
- A visitor without
_fbplands on a page that is already cached. They get the cached copy, PHP never runs, and Meta’s ownfbevents.jssets_fbpin their browser. Fine. - A visitor without
_fbplands on a page that is not cached. PHP builds the page, the plugin sets_fbp, and the cache refuses to store it. The page is still uncached for the next visitor. - A visitor who already has
_fbp(the second page of their visit, or a return visit within the cookie’s 90 days) requests an uncached page. No cookie is set, the cache stores it, and later visitors are served from cache.
So the cache only fills when an already-browsing visitor happens to open a page. That has three consequences:
- Cache preloading does nothing. Preloaders fetch pages without cookies (Hummingbird 4.0.2’s preloader, for example, sends a plain
wp_remote_get()fromcore/modules/caching/class-preload.php), so every preloaded page gets the cookie and is thrown away. - Landing pages stay cold. After every cache clear (a product update, a scheduled purge, a deploy), a page stays uncached until a browsing visitor reaches it. Pages people mostly arrive on from outside, such as product pages reached from Google Shopping, ads or search, can stay uncached for the new visitors who land on them.
- Crawlers never fill the cache, Googlebot included, because they don’t keep cookies.
Check your store first
- Request a product page with no cookies and look for
Set-Cookie:curl -s -o /dev/null -D - "https://yourshop.example/product/something/?nocache=12345"
The made-up query string asks for a fresh render on most caches, because a cached copy never shows you what PHP sends. If anything is set, find the plugin that set it. A response that sets a cookie is never stored, so that page only gets cached when a visitor who already has the cookie opens it. - Check again after any plugin update or a staging refresh from live, and before the Black Friday traffic arrives. The case below arrived through a staging refresh.
How I found it
I do cache work for WooCommerce stores with my Cache Upgrader plugin, which is built on Super Speedy AJAX Prices. Before a store turns caching on for shoppers with a basket, it runs a safety check that requests real pages as different visitors (no cookies, with a basket, from different countries) and compares what comes back, headers included.
A client’s staging site was refreshed from live, and live had Meta for WooCommerce 3.7.8 on it. The next safety run failed on every page tested (home, shop, a category and a product) for the same reason: a visitor arriving with no cookies got a Set-Cookie: _fbp=... header back.
What the plugin does
_fbp is Meta’s browser ID. Meta’s own fbevents.js creates it in the browser, and so does the client-side parameter builder the plugin loads (meta-capi-param-builder-clientjs). The plugin also bundles the server-side half of Meta’s Conversions API parameter builder, and that half sets the same cookie from PHP. In 3.7.8:
- the integration, and with it the events tracker, is built on
initpriority 10 (class-wc-facebookcommerce.php:190); - the tracker’s constructor calls
param_builder_server_setup(), which callssetcookie()for every cookie the parameter builder asks for (facebook-commerce-events-tracker.php:183-225); - the bundled ParamBuilder only creates
_fbpwhen the request doesn’t carry one, gives it a 90-day life (DEFAULT_1PC_AGE), and sets_fbcas well when the URL carries a Facebook click ID (fbclid).
A page cache stores one response and hands it to the next visitor. If that response sets a cookie, every later visitor would get the same cookie value, so caches refuse to store it. The client’s cache was doing the right thing there.
The server-side cookie is also redundant. PHP only sets it when it renders the page, which means on a cache miss. On a cache hit PHP doesn’t run, so the browser has to set _fbp anyway, and Meta’s script does. The browser path therefore always has to work. The server copy adds nothing when the page is cached, and when the page isn’t cached the server copy is what stops it being cached. The only thing it buys is a browser_id on the Conversions API event for that one uncached request. If the aim is a longer-lived cookie than some browsers allow from JavaScript, the place for that is a single uncached request, not every page render.
There’s no setting to turn it off. The plugin’s “isolated pixel” code path is an internal rollout switch (enable_woocommerce_isolated_pixel_execution), not an option a store owner can use. The nearest thing in the code is the facebook_signals_held filter (added in 3.6.0 for consent handling): returning true skips the cookie, but it also holds back the plugin’s server-side events on public pages, which is a much bigger trade than this needs.
The same plugin has a second habit that matters once a page is cached. Each pixel event in the facebook-for-woocommerce-inline script gets a fresh random UUID as its event ID on every render (includes/Events/Event.php:201-230), and Meta uses that ID to deduplicate the browser event against the server event. Cache that page and every visitor shares one set of event IDs. The plugin is partly aware of this: if a page is shown more than 1800 seconds after window.__wc_fb_page_generated, it fires without an event ID. Inside that window a cached page hands the same ID to everyone.
The fix, step by step
The fix is a recipe (a small PHP file for one plugin) in the Cache Upgrader plugin, and it only acts on requests Cache Upgrader treats as cacheable. Cart, checkout, account pages and every POST are left exactly as Meta wrote them.
- Remove the
_fbpand_fbcSet-Cookieheaders and nothing else. - Replace each printed event ID with one generated in the browser for that page view.
- Only act on the exact plugin version that was read, so a Meta update can’t change the behaviour underneath it.
The header removal runs on the wp action, the earliest point Cache Upgrader can tell a cart, checkout or account page from a product page, and still before any output:
add_action('wp', function () {
if (headers_sent() || !ssapco_meta_cacheable_request()) {
return;
}
$kept = array();
$removed = false;
foreach (headers_list() as $header) {
if (0 !== stripos($header, 'Set-Cookie:')) {
continue;
}
if (preg_match('/^Set-Cookie:\s*(_fbp|_fbc)=/i', $header)) {
$removed = true;
} else {
$kept[] = $header;
}
}
if (!$removed) {
return;
}
header_remove('Set-Cookie');
foreach ($kept as $header) {
header($header, false);
}
}, PHP_INT_MAX);
PHP can only remove every Set-Cookie header at once, hence collecting the others and putting them back.
If you adapt this for your own site, ssapco_meta_cacheable_request() is the part to get right. It must only say yes for requests your cache will actually store: GET requests for pages that aren’t the cart, checkout or account pages. Strip the cookie anywhere else and you lose the server-side browser ID for nothing.
2. Give each page view its own event IDs
Each quoted UUID in the inline script becomes a call like ssapcoMetaEventId(0), and a small helper generates a real UUID in the browser with crypto.randomUUID(). The same printed ID always maps to the same browser ID, so the plugin’s fired-events guard and the event’s eventID still agree.
The cost: on a cached page view Meta gets the browser event without a matching server event, which is what the plugin already does itself for pages older than 1800 seconds.
3. Pin it to the version that was read
The recipe only runs on Meta for WooCommerce 3.7.8 exactly. When Meta releases a new version, the recipe stops acting and the safety check goes red until someone reads the new code. That’s deliberate: a fix that keeps running against code nobody has read is how you end up caching something you shouldn’t.
Proving it
The integration test installs the real Meta for WooCommerce 3.7.8 on a test site with the cache layer on. Without the recipe, the _fbp check and the identical-renders check both fail. With it, both pass, and a headless browser load shows each page view firing its own event IDs with no script errors. On the client’s staging site the next safety run had no cookie failures on any page.
Summary
- Meta for WooCommerce 3.7.8 sets
_fbp(and_fbcforfbclidvisits) from PHP on every uncached render for a visitor who doesn’t have it yet. - Page caches won’t store a response that sets a cookie, so new visitors, preloaders and crawlers can’t fill your cache. Only visitors who already carry the cookie can.
- The browser sets the same cookie anyway, so removing the two headers on cacheable pages loses only the server-side browser ID for that one request.
- Its per-render event IDs need replacing in the browser too, or a cached page shares one set of IDs between visitors for up to 1800 seconds.
If you’d rather not write and maintain this yourself, the Meta for WooCommerce recipe is one of the 30 ready-made recipes in the Cache Upgrader Kit for WooCommerce.
Comments