diff --git a/includes/Product_Type.php b/includes/Product_Type.php index 9068f27..de2c959 100644 --- a/includes/Product_Type.php +++ b/includes/Product_Type.php @@ -123,6 +123,11 @@ class Product_Type extends \WC_Product { ], ]; + // Debug logging + if (defined('WP_DEBUG') && WP_DEBUG) { + error_log('Composable Product Criteria: ' . print_r($criteria, true)); + } + switch ($criteria['type']) { case 'category': if (!empty($criteria['categories'])) { @@ -158,9 +163,19 @@ class Product_Type extends \WC_Product { break; } + // Debug logging + if (defined('WP_DEBUG') && WP_DEBUG) { + error_log('Composable Product Query Args: ' . print_r($args, true)); + } + $query = new \WP_Query($args); $products = []; + // Debug logging + if (defined('WP_DEBUG') && WP_DEBUG) { + error_log('Composable Product Query Found: ' . $query->found_posts . ' posts'); + } + if ($query->have_posts()) { foreach ($query->posts as $post) { $product = wc_get_product($post->ID); @@ -173,20 +188,34 @@ class Product_Type extends \WC_Product { if ($product->is_type('variable')) { // Get variation IDs directly from the product $variation_ids = $product->get_children(); + if (defined('WP_DEBUG') && WP_DEBUG) { + error_log('Variable product ' . $product->get_id() . ' has ' . count($variation_ids) . ' variations'); + } foreach ($variation_ids as $variation_id) { $variation = wc_get_product($variation_id); if ($variation && $variation->is_purchasable()) { $products[] = $variation; + if (defined('WP_DEBUG') && WP_DEBUG) { + error_log('Added variation ' . $variation_id . ' - ' . $variation->get_name()); + } } } } elseif ($product->is_purchasable()) { // Simple and other product types $products[] = $product; + if (defined('WP_DEBUG') && WP_DEBUG) { + error_log('Added simple product ' . $product->get_id() . ' - ' . $product->get_name()); + } } } } wp_reset_postdata(); + + if (defined('WP_DEBUG') && WP_DEBUG) { + error_log('Total products available: ' . count($products)); + } + return $products; }