From 252b1876005905aaf90e314d3ae27eb6599170d6 Mon Sep 17 00:00:00 2001 From: magdev Date: Wed, 31 Dec 2025 22:48:17 +0100 Subject: [PATCH] Add variable product support to product selector MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- includes/Product_Type.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/includes/Product_Type.php b/includes/Product_Type.php index 55c1037..49975b6 100644 --- a/includes/Product_Type.php +++ b/includes/Product_Type.php @@ -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; } }