From efedd1bf29f5e52bfd0db57f1087a0704f20a6f7 Mon Sep 17 00:00:00 2001 From: magdev Date: Thu, 1 Jan 2026 02:05:00 +0100 Subject: [PATCH] Add debug logging to product retrieval for troubleshooting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added error_log statements to help diagnose why products aren't showing: - Log selection criteria being used - Log WP_Query arguments - Log number of posts found by query - Log each product being added (variable variations and simple) - Log total products available at end To enable: Set WP_DEBUG to true in wp-config.php Then check debug.log or error.log for output 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 --- includes/Product_Type.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) 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; }