wc-block-visualizer: X-Ray Specs for WooCommerce Block CSS

A tiny vanilla-JS plugin that reveals nested WooCommerce block classes, tracks depth, and generates selectors without a build step.

7 min read • View on GitHub • More from bacoords

A developer studies a stack of transparent WooCommerce block layers while a small HUD labels class names and nesting depth. The scene explains how the plugin turns dense block markup into something you can inspect and target with confidence.
The tool does not hide WooCommerce’s nesting. It makes the stack readable, then gives you a way to move through it.
Key Takeaways

Styling WooCommerce Blocks is rarely hard because the UI is complex. It is hard because the selector you need is hidden several layers down, and the page gives you very little help finding it. wc-block-visualizer exists for that exact moment of friction.

The hardest part of WooCommerce Blocks is not rendering them. It is styling them.

WooCommerce’s block-based cart and checkout screens are built from nested components, not flat templates. That means the obvious selector is often the wrong one, and the right selector is usually buried inside a chain of wrapper elements with names that are easy to overlook.

A depth-aware map of the DOM. The point is not just to identify a block, but to move through nested layers with intent.

That is the problem this repo attacks. Instead of flattening the page into a generic inspector, it adds an opinionated lens for WooCommerce Blocks. The result is closer to an X-ray than a browser tool: you still see the structure, but now you can read it.

This plugin turns the DOM into a navigable map

The implementation is deliberately small. A PHP bootstrap file decides when the tool should load, a vanilla JavaScript engine scans the DOM, and a CSS file draws the overlay without changing layout. No build pipeline. No framework. No extra runtime.

That restraint matters. The plugin is not trying to become a design system, a page builder, or a DevTools replacement. It only wants to answer one question well: what am I looking at, and how do I target it?

A close-up view of nested block layers with one level isolated by a depth meter on the side. A keyboard shortcut panel suggests stepping through layers, while inactive layers fade into the background. The image explains how the plugin lets developers inspect one nesting layer at a time.
The depth filter is the core idea. It reduces overload by letting the user focus on a single nesting layer instead of the whole pile at once.

The depth filter is the real trick

The smartest part of the tool is the currentDepth idea. Instead of forcing the developer to absorb every nested element at once, it filters the view so you can inspect one layer, then step up or down as needed.

That changes the mental model. You are no longer hunting through div soup. You are walking a map. The keyboard shortcut flow makes that feel fast, and the highlighted path keeps the structure legible while you move.

// Depth is the organizing principle.
let currentDepth = 0;

function getElementDepth(el) {
  let depth = 0;
  let parent = el.parentElement;

  while (parent) {
    if (parent.matches('[class*="wc-block"], [class*="wp-block"]')) depth += 1;
    parent = parent.parentElement;
  }

  return depth;
}

function setDepth(nextDepth) {
  currentDepth = Math.max(0, nextDepth);
  renderOverlay();
}

The output is not just visual. It is operational. Once the layer is obvious, the plugin can copy a selector that fits the problem instead of giving you a generic class name you will regret later.

Selector generation is opinionated on purpose

The selector logic prefers WooCommerce-specific classes over generic WordPress wrappers. That sounds small, but it is the kind of opinion that saves time every week. Stable selectors are usually the ones tied most closely to the component, not the broadest ancestor.

ApproachSpeedNesting claritySelector stabilitySetupLayout impact
Manual browser inspectionSlow once nesting gets deepLowMediumNoneNone
General DevTools or brute-force DOM inspectionMediumMediumMediumNoneNone
wc-block-visualizer depth-aware workflowFast for WooCommerce BlocksHighHighNoneNone

The plugin also supports two selector styles. One is a single-class copy for quick targeting. The other is a contextual chain, useful when you want SCSS-friendly output that reflects the nesting path. That split is useful because not every styling task needs the same level of specificity.

In practice, that means the tool is not just finding nodes. It is translating structure into CSS intent.

The implementation is tiny, but the trade-off is smart

The architecture is almost aggressively lean. One server-side file, one client-side engine, one stylesheet. That simplicity keeps the tool easy to audit and easy to drop into a WordPress workflow without ceremony.

There is a product philosophy inside that choice. If the problem is selector discovery, then a heavy abstraction would get in the way. The repo’s size is not an omission. It is the constraint that makes the experience crisp.

Why this matters for WooCommerce’s block future

Tools like this matter because platform shifts are won in the small moments. When developers can read the DOM faster, they adopt blocks faster. When they can trust the selector they copy, they spend less time fighting the interface and more time shipping the customization.

That is why this repo feels bigger than it looks. It does one narrow job, but it does it at the exact point where modern WordPress styling gets expensive. It makes complexity visible, sortable, and CSS-friendly.

Styling workflowWhat it optimizes forBest use case
Browser inspectionGeneral-purpose debuggingBroad front-end work
DevTools and brute-force probingRaw access to the DOMOne-off investigation
wc-block-visualizerDepth-aware selector discoveryWooCommerce Blocks styling