Table of contents :

Finding Products That Are Actually Available

100-days-of-weaviate-035

Table of contents :

For a WooCommerce search experience, a relevant product is not necessarily a sellable product. A vector search can return an item because its description matches the shopper’s query even when the item is out of stock, private, discontinued, or unavailable in the shopper’s region.

Availability should therefore be modeled as structured data and applied as a filter during the Weaviate search. Relevance determines which products match the query; filters determine which matching products are eligible to appear.

Define what “available” means

Before creating a Weaviate schema, agree with the merchant on the business rules behind availability. WooCommerce sites commonly need to distinguish between several states:

  • In stock: The product has a positive inventory quantity.
  • Backorderable: The product has no current stock but can still be purchased.
  • Purchasable: The product can be added to the cart under the current catalog rules.
  • Published: The product is publicly visible in the catalog.
  • Regionally available: The product can be sold or shipped to the shopper’s location.
  • Available for a specific channel: The product can be sold through the storefront, marketplace, wholesale portal, or another channel.

Do not use a single inStock field if the storefront needs more nuanced behavior. A product with zero inventory might still be purchasable on backorder, while a product with inventory might be blocked because it is unpublished or restricted to a customer group.

Model availability as filterable properties

A practical product or offer object can contain denormalized fields such as:

{
  "productId": "4821",
  "name": "Waterproof Hiking Jacket",
  "description": "A lightweight shell for wet-weather hiking.",
  "status": "publish",
  "catalogVisibility": "visible",
  "stockStatus": "instock",
  "stockQuantity": 24,
  "purchasable": true,
  "backordersAllowed": false,
  "salesChannels": ["storefront"],
  "availableRegions": ["US", "CA"]
}

These fields are useful because they can be filtered without parsing the original WooCommerce payload at query time. Keep the names and meanings stable across client projects. For example, define whether purchasable already includes publication, catalog visibility, stock rules, and product-level purchase restrictions.

For a simple store, the minimum useful filter may be status = publish and purchasable = true. For a store with inventory-driven merchandising, also store stockStatus and stockQuantity. Use the quantity for numeric rules such as “at least five units available,” but use the status or purchasable flag for the actual checkout eligibility decision.

Represent variable products at the correct level

Variable products create a common availability mistake. A parent product may be published while every purchasable variation is out of stock. Conversely, only one size or color may be available.

If shoppers search for a specific variation, index variations or sellable offers as separate objects. An offer can contain the parent product ID, variation ID, attributes, price, stock status, and searchable product content. This allows a query such as “blue waterproof jacket in medium” to return an offer that is actually available in that combination.

If the search experience is intentionally product-level, maintain an aggregate field on the parent product, such as hasAvailableOffer. Update it whenever variation inventory changes. Do not infer parent availability from a stale snapshot of the parent product alone.

Combine semantic search with an availability filter

Weaviate applies filters alongside vector or hybrid search. The filter does not make an unavailable product more relevant; it excludes the object before the result set is returned.

For example, a GraphQL query can require a published, purchasable product with stock while still using semantic search for the shopper’s wording:

query {
  Products(
    nearText: { concepts: ["lightweight jacket for rainy hikes"] }
    where: {
      operator: And
      operands: [
        { path: ["status"], operator: Equal, valueText: "publish" },
        { path: ["purchasable"], operator: Equal, valueBoolean: true },
        { path: ["stockStatus"], operator: Equal, valueText: "instock" }
      ]
    }
    limit: 12
  ) {
    productId
    name
    stockStatus
    stockQuantity
    _additional {
      distance
    }
  }
}

For a storefront that permits backorders, replace the stock-only condition with the business rule that represents checkout eligibility. For example, filtering on purchasable = true may be more accurate than requiring stockStatus = instock.

Use numeric filters for inventory thresholds

Inventory quantities are useful for operational or merchandising requirements. A retailer might want to hide products with fewer than three units available, or show only products with enough stock for a campaign.

In the Weaviate Python client, a filter can be expressed in a form similar to:

from weaviate.classes.query import Filter

availability_filter = (
    Filter.by_property("status").equal("publish")
    & Filter.by_property("purchasable").equal(True)
    & Filter.by_property("stockQuantity").greater_than(2)
)

response = collection.query.near_text(
    query="lightweight jacket for rainy hikes",
    filters=availability_filter,
    limit=12,
    return_properties=["productId", "name", "stockStatus", "stockQuantity"]
)

Use numeric quantities for threshold decisions, not as a substitute for WooCommerce’s stock rules. A quantity of zero can still be purchasable when backorders are enabled, and a positive quantity can still be unavailable because of a catalog or fulfillment restriction.

Filter by region and sales channel

Availability is often dependent on the request context. A product may be in stock but unavailable for shipment to a particular country, or available in the storefront but not in a wholesale channel.

Store region and channel values as filterable properties, then include the shopper’s context in the query:

where: {
  operator: And,
  operands: [
    { path: ["purchasable"], operator: Equal, valueBoolean: true },
    { path: ["salesChannels"], operator: ContainsAny, valueTextArray: ["storefront"] },
    { path: ["availableRegions"], operator: ContainsAny, valueTextArray: ["US"] }
  ]
}

The exact client syntax depends on the Weaviate API and client version used by the project. Validate the filter operators against the deployed version and property data types. Array fields must be configured and queried consistently; a text field containing comma-separated country codes is harder to filter reliably than a proper text-array property.

Keep the search index synchronized with WooCommerce

Availability data becomes dangerous when it is treated as permanent catalog content. Product descriptions may change occasionally, but inventory can change after every order, cancellation, refund, stock adjustment, or warehouse synchronization.

An agency integration should define an update path for at least these events:

  • Product publication or unpublication.
  • Stock quantity or stock status changes.
  • Backorder setting changes.
  • Variation creation, deletion, or attribute changes.
  • Price, channel, or regional availability changes.
  • Order placement, cancellation, refund, or external warehouse update.

Use the WooCommerce database or inventory service as the source of truth. Weaviate should be a search projection. When an event arrives, update the affected object rather than waiting for a full catalog reindex. A scheduled reconciliation job is still valuable for detecting missed webhooks and correcting drift.

For high-volume stores, include an inventory version or last-updated timestamp in the indexed object. This helps operators compare Weaviate with the commerce system and identify stale records. It does not replace a real-time stock reservation or final availability check during checkout.

Do not rely on search filtering for checkout validation

A filtered search result is only a point-in-time representation. Another shopper may purchase the last unit before the first shopper reaches checkout. WooCommerce or the connected inventory service must perform the authoritative stock and purchasability check when the item is added to the cart and again when the order is created.

The search API should also handle stale results gracefully. If a shopper opens a product that has just become unavailable, the product page and cart should display the current commerce-system state rather than trusting the values returned by Weaviate.

Test edge cases with realistic fixtures

Availability tests should cover combinations rather than only checking a single in-stock product. Useful fixtures include:

  1. A published simple product with positive stock.
  2. A published product with zero stock and backorders disabled.
  3. A published product with zero stock and backorders enabled.
  4. An unpublished product with positive stock.
  5. A variable product whose parent is published but whose matching variation is unavailable.
  6. A product available in one country but not another.
  7. A product available in the storefront but not in the wholesale channel.
  8. A product whose WooCommerce stock changed after its Weaviate object was indexed.

For each fixture, verify both semantic relevance and filter behavior. A product should not appear merely because its description strongly matches the query. Also verify that removing the availability filter produces the expected diagnostic results; this makes it easier to distinguish a poor embedding from an incorrect filter or stale synchronization data.

Implementation checklist for WooCommerce agencies

  • Define “available” with the merchant before designing the schema.
  • Store availability as typed, filterable properties rather than text embedded in descriptions.
  • Index variations or offers when availability depends on size, color, or another option.
  • Use semantic or hybrid search for relevance and Weaviate filters for eligibility.
  • Represent backorders explicitly instead of assuming zero stock always means unavailable.
  • Include region and sales-channel constraints when the store needs them.
  • Update inventory fields from WooCommerce events and run periodic reconciliation.
  • Perform the final stock check in WooCommerce or the inventory system at cart and checkout time.
  • Test stale data, variation-level stock, and contradictory product states before launch.
Trending posts
You might also like