Skip to content

Add include/exclude category filters to the Product Categories block - #320

Merged
davidperezgar merged 3 commits into
trunkfrom
feature/product-categories-include-exclude
Oct 2, 2026
Merged

davidperezgar merged 3 commits into
trunkfrom
feature/product-categories-include-exclude

Conversation

@Castellon-ACM

@Castellon-ACM Castellon-ACM commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Editors can now pick which product categories the block shows (include) and which to always hide (exclude), with nested parent/child categories shown as "Parent > Child" in the picker. When a category is listed in both, exclude wins. Default behaviour (no filters set) is unchanged.

Closes #308

Open WordPress Playground Preview

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

Editors can now pick which product categories the block shows (include)
and which to always hide (exclude), with nested parent/child categories
shown as "Parent > Child" in the picker. When a category is listed in
both, exclude wins. Default behaviour (no filters set) is unchanged.

Closes #308

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@Castellon-ACM
Castellon-ACM force-pushed the feature/product-categories-include-exclude branch from 9697aa6 to d7857b6 Compare October 2, 2026 06:43
@davidperezgar

Copy link
Copy Markdown
Contributor

@Castellon-ACM revisas esto?
P1 — Cuando una categoría está tanto en include como en exclude y todas las incluidas quedan excluidas, el bloque termina mostrando todas las categorías. resolve_category_filters() devuelve ambos filtros vacíos, así que get_terms() no recibe restricción. El comportamiento esperado es no mostrar ninguna. Ver línea 345.

P2 — El selector carga solo per_page=100; en tiendas con más de 100 categorías, las restantes no se pueden incluir ni excluir desde el editor. Debe paginar la REST API (o implementar una búsqueda remota). Ver línea 139.

P1 — resolve_category_filters() returned both include and exclude
empty when every included category was also excluded, which get_terms()
reads as "no restriction" and shows every category instead of none.
Fall back to include => [0] (never a valid term ID) in that case, so
the query matches zero terms. Mirrored the same fix in the editor's
preview query (frontblocks-product-categories-option.jsx) using the
same include=0 sentinel, and updated the test that had asserted the
old, buggy expectation.

P2 — the include/exclude picker loaded a flat per_page=100 list of
every store category up front, so categories beyond the first 100
could never be selected. Replaced that with: resolve only the
categories already selected by ID (plus one extra round-trip for any
unresolved parent, for "Parent > Child" labels), and a 250ms-debounced
live search (REST `search` param, 20 results per keystroke) for the
picker's suggestions. Works regardless of how many categories a store
has.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@davidperezgar
davidperezgar merged commit 3680e41 into trunk Oct 2, 2026
7 checks passed
@davidperezgar
davidperezgar deleted the feature/product-categories-include-exclude branch October 2, 2026 08:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for excluding/including product categories in the product-categories block's query

2 participants