// Add WooCommerce attribute to Elementor dynamic tags
add_action('elementor/dynamic_tags/register', function($dynamic_tags) {
    
    class Product_Attribute_Tag extends \Elementor\Core\DynamicTags\Tag {
        
        public function get_name() {
            return 'product-attribute';
        }
        
        public function get_title() {
            return 'Product Attribute';
        }
        
        public function get_group() {
            return 'woocommerce';
        }
        
        public function get_categories() {
            return [ \Elementor\Modules\DynamicTags\Module::TEXT_CATEGORY ];
        }
        
        protected function register_controls() {
            $this->add_control(
                'attribute',
                [
                    'label' => 'Attribute',
                    'type' => \Elementor\Controls_Manager::SELECT,
                    'options' => [
                        'pa_designer' => 'Designer',
                        'pa_neckline' => 'Neckline',
                        'pa_sleeve' => 'Sleeve',
                        'pa_back' => 'Back',
                        'pa_fabric' => 'Fabric',
                        // Add all your attributes here
                    ],
                ]
            );
        }
        
        public function render() {
            $attribute = $this->get_settings('attribute');
            $product_id = get_the_ID();
            
            $terms = get_the_terms($product_id, $attribute);
            if ($terms && !is_wp_error($terms)) {
                $term_names = wp_list_pluck($terms, 'name');
                echo implode(', ', $term_names);
            }
        }
    }
    
    $dynamic_tags->register(new Product_Attribute_Tag());
});