Skip to main content

3 posts tagged with "Theme Development"

View all tags

WooCommerce Checkout Template Not Applied? Plugin Override

Β· 5 min read

After assigning the theme's checkout template to the Checkout page, the front end still renders WooCommerce's own structure β€” the theme template's heading and footer are nowhere in the output, while the body class reports the assignment as active.

Ran into this while building a minimal FSE WordPress theme for a client β€” a full-site-editing theme for corporate sites and lightweight e-commerce, with WooCommerce compatibility kept intentionally thin.

TL;DR​

WooCommerce hooks page_template_hierarchy at priority 1 and unshifts its own template slugs (checkout, cart) to the front of the hierarchy array, so the plugin template outranks nearly every candidate. Manually setting _wp_page_template on the page at that point only creates a second, conflicting signal β€” the body class reads the meta while the render follows the filter. The fix: delete the manually set _wp_page_template and let the hierarchy filter resolve.

Symptom: Body Class Says Theme Template, Render Is the Plugin's​

The template assignment in the page editor clearly names the theme's checkout template, and the body class faithfully shows page-template-checkout; the front-end output, however, is WooCommerce's page-content-wrapper β€” store notices and product content only, none of the heading and footer structure from the theme template.

The diagnostic marker is a single attribute: check whether the page's <main> element carries data-block-name="woocommerce/page-content-wrapper". If it does, WooCommerce's plugin template is what actually renders β€” the theme template has been sidelined, confirmed.

A symptom as self-contradictory as "body class says A, render shows B" almost always means two signal sources that never sync β€” and this machine has exactly one such pair.

Root Cause: page_template_hierarchy Cuts In at Priority 1​

WooCommerce's AbstractPageTemplate registers the filter in init():

add_filter( 'page_template_hierarchy', array( $this, 'page_template_hierarchy' ), 1 );

The callback is a one-line array_unshift: when the page matches the Checkout/Cart scenario, its own template slug goes to the front of the candidate array. The source comments state it plainly β€” priority 1 is deliberate, to run first; extensions using the default priority 10 line up behind it.

WordPress resolves templates by walking the array and taking the first file that exists. With checkout at the front: if the theme ships a template file of that name, the theme's wins; if not, resolution lands on WooCommerce's registered plugin template of the same slug (page-checkout.html, containing the woocommerce/page-content-wrapper structure).

Why does manually setting _wp_page_template backfire? That meta only feeds the body class and the editor display β€” it never enters the filter's resolution order. Its signal and the filter's result travel on separate tracks, producing the stalemate "assignment shows active, render doesn't move".

Fix: Delete _wp_page_template and Let the Hierarchy Filter Resolve​

Delete the manually set template meta and let WooCommerce's resolution mechanism run:

wp post meta delete <page_id> _wp_page_template

After deletion, body class and render agree again: whatever the filter resolves is what renders, and the body class reflects it. No template meta should be set explicitly on pages WooCommerce owns β€” the hierarchy filter is the authoritative signal.

A separate structural pitfall of the Cart template (placeholders and SSR rendering) lives at the same template layer and is worth checking alongside Checkout.

Caution

When verifying the fix, do not set _wp_page_template back "just to test" β€” that is the very source of the conflicting signal. The Cart page runs the same mechanism; if it shows the same assignment-ignored behavior, treat it identically, diagnosing with the same data-block-name="woocommerce/page-content-wrapper" marker.

FAQ​

How does WooCommerce win template resolution?​

It hooks page_template_hierarchy at priority 1, earlier than consumers at the default priority 10, and unshifts its template slug to the front of the hierarchy array. The WooCommerce source comments state this priority is intentional.

Why do the body class and the actual render disagree?​

Two separate signal sources: the body class is generated directly from the _wp_page_template meta, while the rendered template is decided by the hierarchy filter's array order. A manually set meta falls out of sync with the filter's result.

How do I confirm the plugin template is the one rendering?​

There is exactly one reliable marker: the data-block-name attribute on the main element. data-block-name="woocommerce/page-content-wrapper" means the plugin template renders; a theme-template main is built from the theme's own blocks and carries no such marker.

Is the Cart page taken over the same way?​

Yes. The same AbstractPageTemplate mechanism has two implementations, CartTemplate and CheckoutTemplate, covering both the Cart and Checkout pages β€” the same data-block-name marker diagnoses them.

CCLEE

Independent developer, 24 years in e-commerce, focused on grounding AI in real business scenarios.

Work with me

WooCommerce Gallery Images Not Loading? FlexSlider Conflict

Β· 6 min read

Flipping through the product gallery thumbnails on a WooCommerce product page, everything works until slide seven β€” from there the main image stays blank, and the DevTools Network panel shows no request was ever sent.

Ran into this while building a minimal FSE WordPress theme for a client β€” a full-site-editing theme for corporate sites and lightweight e-commerce, with WooCommerce compatibility kept intentionally thin. The issue was ultimately fixed inside the theme with a single filter.

TL;DR​

WordPress 5.5+ automatically injects loading="lazy" into content images, while WooCommerce's FlexSlider gallery moves non-active slides out of the viewport with CSS transforms. Together, the IntersectionObserver that native lazy loading depends on never sees those images enter its trigger range β€” no request is ever sent. The fix: a wp_get_attachment_image_attributes filter that removes the loading attribute for the woocommerce_single size only.

The first few gallery images render fine; from a certain slide onward the main image area stays blank. The same problem surfaces under searches like "gallery images not showing" or "product images won't load".

DevTools shows three facts at once:

  1. The <img> node exists with a valid src attribute;
  2. The <img> carries loading="lazy";
  3. The Network panel has no matching request β€” not a failed load, the browser never started the download.

"A src but no request" is the dividing line between this problem and image 404s or broken paths: those show requests and errors, this one is completely silent.

Root Cause: Native Lazy Loading Stacked on Slider Off-Screen Layout​

Every gallery image sits in the state "has a src, not visible, waiting for the browser to decide" β€” and FlexSlider's layout makes the "visible" condition permanently unreachable. The mechanism has three layers:

Layer 1: WordPress injects lazy loading automatically. Since WordPress 5.5, images output by wp_get_attachment_image() carry loading="lazy" by default (the first image excepted). Product gallery main images use the woocommerce_single size, so all of them match this rule. The intent is bandwidth savings: only load images near the viewport.

Layer 2: FlexSlider moves non-active frames off-screen. FlexSlider arranges all slides in one horizontal strip; slides outside the current frame sit beyond the viewport and swap positions via CSS transforms.

Layer 3: IntersectionObserver's trigger condition is never met. Browser lazy loading is not "load when visible" but "preload when within a threshold" β€” about 1250px for images on desktop Chrome, expanding to 2500px on slow connections. In a horizontal slider, the distance between slide N and the viewport grows linearly with its index; past the threshold, IntersectionObserver never fires. In practice, from slide seven onward not a single request goes out.

The entire chain throws no error: the img has a src, the page logs no JS exception, the server log is clean β€” the browser simply classified those images as "not needed yet". That is what makes this expensive to diagnose: each component behaves exactly as documented, and the combination deadlocks.

A wp_get_attachment_image_attributes filter that unsets loading for woocommerce_single images returns gallery images to default eager loading, and the problem disappears.

add_filter(
'wp_get_attachment_image_attributes',
function ( $attr, $attachment, $size ) {
if ( 'woocommerce_single' === $size ) {
unset( $attr['loading'] );
}
return $attr;
},
10,
3
);

Drop it into the theme's functions.php or an inc module; child theme users should put it in the child's functions.php without touching the parent.

Why it works: once the loading attribute is gone, the browser falls back to immediate loading β€” requests fire during HTML parsing, and FlexSlider's positioning only affects display from then on, never loading. Ordinary content images never pass through a slider, so their lazy loading works and should stay; gallery images have their visibility managed by the slider, so the loading decision goes back to the browser default.

CCLEE Theme ships this filter built in (inc/woocommerce.php) β€” update the theme and you are covered.

If you are also chasing other WooCommerce block theme rendering issues, gallery problems tend to appear alongside template structure issues, so it is worth reviewing both.

Caution

Do not remove loading globally for convenience β€” immediate loading for everything below the fold slows the page down, and lazy loading is a pure win for body images. Keep the condition locked to the woocommerce_single size. If you switch sliders (e.g. Swiper), check whether the new slider ships its own lazy-loading module first to avoid stacking two mechanisms.

FAQ​

Why do images with a src attribute never trigger a network request?​

loading="lazy" hands the timing to the browser: when an image sits beyond the preload threshold (about 1250px on desktop Chrome), IntersectionObserver never fires and the request is never sent. A src value only means the DOM is ready β€” loading depends on the visibility check.

Can I just remove all loading="lazy" attributes site-wide?​

It fixes the gallery, but every image below the fold switches to immediate loading, costing bandwidth and competing with LCP resources. Keep global lazy loading and strip the attribute only for the woocommerce_single size with a filter.

Which slider libraries cause the same problem?​

Any horizontal slider that moves non-active frames out of the viewport: FlexSlider, Swiper, Slick, and similar. If the slider ships its own lazy-loading module (like Swiper's lazy option), use that and remove the native loading attribute to avoid conflicting mechanisms.

Since which WordPress version does this problem exist?​

WordPress 5.5 (2020) introduced native lazy loading, and since 5.9 every content image except the first gets loading="lazy" by default. The problem appears whenever a product gallery uses a translating slider, regardless of WooCommerce or slider version.

CCLEE

Independent developer, 24 years in e-commerce, focused on grounding AI in real business scenarios.

Work with me

Fix WordPress FSE Pattern Block Validation Errors - 5 Common Causes

Β· 4 min read

Encountered frequent Block Pattern validation failures while developing a WordPress FSE theme for a client. This article summarizes 5 common causes and solutions.

TL;DR​

Block validation failures are usually caused by one of: undefined color slugs, duplicate JSON keys, Style Variation palette override, HTML attribute mismatch with block comments, or global styles overriding theme.json. Check each one systematically.