// Add these filters to the wux-attribute-debug.php file /** * Monitor the add_attribute_to_product function */ function wux_debug_add_attribute() { if (!class_exists('Wux\\Modules\\Woocommerce\\ProductMapping')) return; // Create a new instance for debugging purposes only $original_class = new \ReflectionClass('Wux\\Modules\\Woocommerce\\ProductMapping'); if ($original_class->hasMethod('add_attribute_to_product')) { $original_method = $original_class->getMethod('add_attribute_to_product'); $original_method->setAccessible(true); // Override the method to add logging add_filter('wux_debug_add_attribute', function($product, $attribute_slug, $term_id) { wux_attr_log("ADD_ATTRIBUTE_TO_PRODUCT called for product ID: {$product->get_id()}, slug: {$attribute_slug}, term: {$term_id}", 'info', true); // Log existing attributes $product_attributes = $product->get_attributes(); $attribute_keys = array_keys($product_attributes); wux_attr_log("Before adding attribute, product has: " . implode(', ', $attribute_keys), 'info', true); return [$product, $attribute_slug, $term_id]; }, 10, 3); } } // Initialize at a very late priority to ensure all classes are loaded add_action('wp_loaded', 'wux_debug_add_attribute', 999); /** * Add a global filter to capture any direct attribute updates via WooCommerce API */ add_filter('woocommerce_update_product_attribute', function($attribute_id, $data) { wux_attr_log("DIRECT ATTRIBUTE UPDATE for ID {$attribute_id}: " . print_r($data, true), 'info', true); return $attribute_id; }, 10, 2);