You've already forked wc-composable-product
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:
@@ -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']) {
|
switch ($criteria['type']) {
|
||||||
case 'category':
|
case 'category':
|
||||||
if (!empty($criteria['categories'])) {
|
if (!empty($criteria['categories'])) {
|
||||||
@@ -158,9 +163,19 @@ class Product_Type extends \WC_Product {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Debug logging
|
||||||
|
if (defined('WP_DEBUG') && WP_DEBUG) {
|
||||||
|
error_log('Composable Product Query Args: ' . print_r($args, true));
|
||||||
|
}
|
||||||
|
|
||||||
$query = new \WP_Query($args);
|
$query = new \WP_Query($args);
|
||||||
$products = [];
|
$products = [];
|
||||||
|
|
||||||
|
// Debug logging
|
||||||
|
if (defined('WP_DEBUG') && WP_DEBUG) {
|
||||||
|
error_log('Composable Product Query Found: ' . $query->found_posts . ' posts');
|
||||||
|
}
|
||||||
|
|
||||||
if ($query->have_posts()) {
|
if ($query->have_posts()) {
|
||||||
foreach ($query->posts as $post) {
|
foreach ($query->posts as $post) {
|
||||||
$product = wc_get_product($post->ID);
|
$product = wc_get_product($post->ID);
|
||||||
@@ -173,20 +188,34 @@ class Product_Type extends \WC_Product {
|
|||||||
if ($product->is_type('variable')) {
|
if ($product->is_type('variable')) {
|
||||||
// Get variation IDs directly from the product
|
// Get variation IDs directly from the product
|
||||||
$variation_ids = $product->get_children();
|
$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) {
|
foreach ($variation_ids as $variation_id) {
|
||||||
$variation = wc_get_product($variation_id);
|
$variation = wc_get_product($variation_id);
|
||||||
if ($variation && $variation->is_purchasable()) {
|
if ($variation && $variation->is_purchasable()) {
|
||||||
$products[] = $variation;
|
$products[] = $variation;
|
||||||
|
if (defined('WP_DEBUG') && WP_DEBUG) {
|
||||||
|
error_log('Added variation ' . $variation_id . ' - ' . $variation->get_name());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} elseif ($product->is_purchasable()) {
|
} elseif ($product->is_purchasable()) {
|
||||||
// Simple and other product types
|
// Simple and other product types
|
||||||
$products[] = $product;
|
$products[] = $product;
|
||||||
|
if (defined('WP_DEBUG') && WP_DEBUG) {
|
||||||
|
error_log('Added simple product ' . $product->get_id() . ' - ' . $product->get_name());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wp_reset_postdata();
|
wp_reset_postdata();
|
||||||
|
|
||||||
|
if (defined('WP_DEBUG') && WP_DEBUG) {
|
||||||
|
error_log('Total products available: ' . count($products));
|
||||||
|
}
|
||||||
|
|
||||||
return $products;
|
return $products;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user