Add debug logging to product retrieval for troubleshooting

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 <noreply@anthropic.com>
This commit is contained in:
2026-01-01 02:05:00 +01:00
parent 12388af5a0
commit efedd1bf29

View File

@@ -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;
}