From 5129ff9aea769f740c07e090b60a979db9a6b00d Mon Sep 17 00:00:00 2001 From: dwindown Date: Thu, 20 Nov 2025 01:03:34 +0700 Subject: [PATCH] fix: Use correct meta key format for variation attributes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Found the issue from debug log: - WooCommerce stores as: attribute_Color (exact case match) - We were trying: attribute_color (lowercase) ❌ Fixed: - Use 'attribute_' + exact attribute name - get_post_meta with true flag returns single value (not array) Result: - Variation #362: {"Color": "Red"} ✅ - Variation #363: {"Color": "Blue"} ✅ Removed debug logging as requested. --- includes/Api/ProductsController.php | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/includes/Api/ProductsController.php b/includes/Api/ProductsController.php index d391db6..472be24 100644 --- a/includes/Api/ProductsController.php +++ b/includes/Api/ProductsController.php @@ -599,10 +599,6 @@ class ProductsController { // Format attributes with human-readable names and values $formatted_attributes = []; - // Debug: Log all meta for this variation - $all_meta = get_post_meta($variation_id); - error_log("Variation #{$variation_id} ALL META: " . print_r($all_meta, true)); - // Get parent product attributes to know what to look for $parent_attributes = $product->get_attributes(); @@ -626,17 +622,10 @@ class ProductsController { $value = $term ? $term->name : $value; } } else { - // Custom attribute - get the value from variation meta - // WooCommerce stores it as 'attribute_' + lowercase attribute name - $meta_key = 'attribute_' . strtolower($attr_name); + // Custom attribute - WooCommerce stores as 'attribute_' + exact attribute name + $meta_key = 'attribute_' . $attr_name; $value = get_post_meta($variation_id, $meta_key, true); - // If not found, try with sanitized title - if (empty($value)) { - $meta_key = 'attribute_' . sanitize_title($attr_name); - $value = get_post_meta($variation_id, $meta_key, true); - } - // Capitalize the attribute name for display $clean_name = ucfirst($attr_name); }