Add variable product support to product selector

BREAKING CHANGE: Variable products now supported in composable products.

Changes:
- Modified get_available_products() to detect variable products
- Variable products now expand to show all available variations
- Each variation is checked individually for stock and purchasability
- Simple products continue to work as before

This allows customers to select specific variations (e.g., "T-Shirt - Red - Large")
instead of just seeing "T-Shirt" which wasn't selectable.

Fixes the issue where products weren't showing because all products
in the category/tag were variable products.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
2025-12-31 22:48:17 +01:00
parent 8185a77697
commit 252b187600

View File

@@ -163,7 +163,22 @@ class Product_Type extends \WC_Product {
if ($query->have_posts()) {
foreach ($query->posts as $post) {
$product = wc_get_product($post->ID);
if ($product && $product->is_in_stock() && $product->is_purchasable()) {
if (!$product) {
continue;
}
// Handle variable products by including their variations
if ($product->is_type('variable')) {
$variations = $product->get_available_variations();
foreach ($variations as $variation_data) {
$variation = wc_get_product($variation_data['variation_id']);
if ($variation && $variation->is_in_stock() && $variation->is_purchasable()) {
$products[] = $variation;
}
}
} elseif ($product->is_in_stock() && $product->is_purchasable()) {
// Simple and other product types
$products[] = $product;
}
}