fix: Use correct meta key format for variation attributes
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.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user