Product Details and Variation Selection
Match product attributes and variations while keeping selection feedback distinct from server stock validation.
Product details and variation selection
useWpProductVariations(productOrId) accepts a product object, numeric ID, string SKU or null. Passing the object supplies the product directly, although the implementation still invokes its product hook.
Its result includes product, attributes, selectedAttributes, setAttribute, setAttributes, resetAttributes, matchingVariation, isSelectionComplete, currentPrice, currentRegularPrice, currentImage, currentStockStatus, isOutOfStock and isOnSale.
Attribute keys/values must exactly match variation records. Options can be strings or ProductAttributeOption objects. A partial selection can update the display without identifying a complete purchasable variation.
Display feedback is not a stock reservation
Require a complete selection, a matching variation and availability before enabling an add action. The server must validate ownership, attributes, quantity and current stock again. Base-product price/image fallbacks do not prove a choice is valid.
WpProductGallery, WpProductPrice, WpProductVariationSelector, WpProductStockStatus, WpRelatedProducts and WpProductReviews accept numeric productId props. Most provide styled markup; use headless hooks for custom interfaces.
Try the variation exercise and worked solution, then verify equivalent real products before accepting a cart integration.