diff --git a/includes/Api/ProductsController.php b/includes/Api/ProductsController.php index dbf7a20..4d9a373 100644 --- a/includes/Api/ProductsController.php +++ b/includes/Api/ProductsController.php @@ -608,7 +608,7 @@ class ProductsController { } $attr_name = $parent_attr->get_name(); - $clean_name = $parent_attr->get_name(); // Already clean for custom attributes + $clean_name = $attr_name; // Get the variation's value for this attribute if (strpos($attr_name, 'pa_') === 0) { @@ -622,8 +622,19 @@ class ProductsController { $value = $term ? $term->name : $value; } } else { - // Custom attribute - get from meta - $value = get_post_meta($variation_id, 'attribute_' . sanitize_title($attr_name), true); + // Custom attribute - get the value from variation meta + // WooCommerce stores it as 'attribute_' + lowercase attribute name + $meta_key = 'attribute_' . strtolower($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); } $formatted_attributes[$clean_name] = $value;