WooCommerce Overview
The three shop widgets, their query layer, AJAX endpoints and graceful degradation without WooCommerce.
Three widgets run real WooCommerce queries server-side. They are bespoke rather than schema-driven precisely because a WC_Query and AJAX pagination cannot be expressed as a field schema.
The three widgets#
| Widget | Element class | Query layer | Editor preview |
|---|---|---|---|
| Products Grid | Jalpi_Element_Products_Grid | Jalpi_Woo_Query | ProductsGridPreview |
| Product Categories | Jalpi_Element_Product_Categories | Jalpi_Woo_Terms | ProductCategoriesPreview |
| Single Product | Jalpi_Element_Single_Product | WooCommerce template tags | SingleProductPreview |
The query layer#
Jalpi_Woo_Query::build_args( $content, $limit, $page ) translates widget content into WP_Query arguments and returns them through the jalpi_products_grid_query_args filter. It handles nine source values β latest, featured, sale, best-selling, top-rated, related, upsells, cross-sells, manual β plus taxonomy filters, include/exclude id lists, stock status, ordering and offset.
Three private helpers do the input hardening: ids() (digits only), slugs() (slug or numeric id) and contextual_ids() (resolves related, upsells and cross-sells against the current product).
Jalpi_Woo_Terms::build_args() does the same for product_cat, filtered through jalpi_product_categories_args.
AJAX#
Jalpi_Woo_Ajax registers four handlers β two actions, each for logged-in and anonymous visitors:
| Action | Purpose | Parameters |
|---|---|---|
jalpi_pg_page | Returns one page of product-card HTML | nonce, post, node, page |
jalpi_pg_cart | Adds a product to the cart | nonce, product id, quantity |
Two design decisions are worth copying:
- The query never travels over the wire. Only
post,nodeandpageare sent; the handler loads the saved node from the database and rebuilds the query from it, so a client cannot craft an arbitrary product query. - The card markup has one implementation. Rather than duplicating it,
render_card_via_element()usesClosure::bind()to call the elementβs privaterender_card()method, so AJAX pages and the server-rendered first page can never drift apart.
Access control: the post must be published, or the user must pass read_post. jalpi_pg_cart self-guards on WooCommerce being loaded and runs the core woocommerce_add_to_cart_validation filter.
Without WooCommerce#
Jalpi_Woo_Ajax::instance() is registered unconditionally so the grid still paginates even with WooCommerce inactive. Two placeholder classes stand in for the real objects:
Jalpi_Woo_Placeholderβ implements theWC_Productsurface the card renderer uses (get_name(),get_price_html(),get_sku(),is_on_sale(),get_average_rating(), and so on).Jalpi_Woo_Term_Placeholderβ the same idea forproduct_catterms.
The editor also receives hasWoo in jalpiEditorConfig, so the inspector hides shop-only controls rather than offering links that cannot work.
Storefront theming#
Jalpi_Woo::init_frontend() runs when the class exists and adds a jalpi-kit-{id} body class from the jalpi_active_kit option. All kit-specific WooCommerce styling is scoped to that class, which is why importing a light kit over a dark one does not leave the two fighting.
It also provides a cart-count fragment and a small inline sync script so the header cart badge updates after an AJAX add-to-cart.
Source
Files
includes/class-jalpi-woo.php includes/class-jalpi-woo-query.php includes/class-jalpi-woo-terms.php includes/class-jalpi-woo-ajax.php includes/elements/class-jalpi-element-products-grid.php includes/elements/class-jalpi-element-product-categories.php includes/elements/class-jalpi-element-single-product.php admin/editor/src/widgets/ProductsGridPreview.tsx
Classes
Jalpi_Woo Jalpi_Woo_Query Jalpi_Woo_Terms Jalpi_Woo_Ajax Jalpi_Woo_Placeholder Jalpi_Woo_Term_Placeholder Jalpi_Element_Products_Grid
Functions
build_args run max_pages handle_page handle_cart init_frontend is_active cart_count
Last updated: November 2026