start_controls_section( 'content_section', [ 'label' => __('Content', 'cannaiq-menus'), 'tab' => \Elementor\Controls_Manager::TAB_CONTENT, ] ); $this->add_control( 'source', [ 'label' => __('Strain Source', 'cannaiq-menus'), 'type' => \Elementor\Controls_Manager::SELECT, 'default' => 'auto', 'options' => [ 'auto' => __('Auto (from product)', 'cannaiq-menus'), 'custom' => __('Custom value', 'cannaiq-menus'), ], ] ); $this->add_control( 'custom_strain', [ 'label' => __('Strain Type', 'cannaiq-menus'), 'type' => \Elementor\Controls_Manager::SELECT, 'default' => 'hybrid', 'options' => [ 'sativa' => __('Sativa', 'cannaiq-menus'), 'indica' => __('Indica', 'cannaiq-menus'), 'hybrid' => __('Hybrid', 'cannaiq-menus'), ], 'condition' => [ 'source' => 'custom', ], ] ); $this->add_control( 'format', [ 'label' => __('Display Format', 'cannaiq-menus'), 'type' => \Elementor\Controls_Manager::SELECT, 'default' => 'pill', 'options' => [ 'pill' => __('Pill', 'cannaiq-menus'), 'text' => __('Text Only', 'cannaiq-menus'), ], ] ); $this->add_control( 'text_format', [ 'label' => __('Text Format', 'cannaiq-menus'), 'type' => \Elementor\Controls_Manager::SELECT, 'default' => 'uppercase', 'options' => [ 'uppercase' => __('UPPERCASE', 'cannaiq-menus'), 'capitalize' => __('Capitalize', 'cannaiq-menus'), 'lowercase' => __('lowercase', 'cannaiq-menus'), ], ] ); $this->add_control( 'show_icon', [ 'label' => __('Show Icon', 'cannaiq-menus'), 'type' => \Elementor\Controls_Manager::SWITCHER, 'label_on' => __('Yes', 'cannaiq-menus'), 'label_off' => __('No', 'cannaiq-menus'), 'return_value' => 'yes', 'default' => '', ] ); $this->end_controls_section(); // Style Section $this->start_controls_section( 'style_section', [ 'label' => __('Style', 'cannaiq-menus'), 'tab' => \Elementor\Controls_Manager::TAB_STYLE, ] ); $this->add_control( 'size', [ 'label' => __('Size', 'cannaiq-menus'), 'type' => \Elementor\Controls_Manager::SELECT, 'default' => 'medium', 'options' => [ 'small' => __('Small', 'cannaiq-menus'), 'medium' => __('Medium', 'cannaiq-menus'), 'large' => __('Large', 'cannaiq-menus'), ], ] ); $this->add_control( 'sativa_color', [ 'label' => __('Sativa Color', 'cannaiq-menus'), 'type' => \Elementor\Controls_Manager::COLOR, 'default' => '#22c55e', ] ); $this->add_control( 'indica_color', [ 'label' => __('Indica Color', 'cannaiq-menus'), 'type' => \Elementor\Controls_Manager::COLOR, 'default' => '#8b5cf6', ] ); $this->add_control( 'hybrid_color', [ 'label' => __('Hybrid Color', 'cannaiq-menus'), 'type' => \Elementor\Controls_Manager::COLOR, 'default' => '#f97316', ] ); $this->add_group_control( \Elementor\Group_Control_Typography::get_type(), [ 'name' => 'typography', 'selector' => '{{WRAPPER}} .cannaiq-strain-badge', ] ); $this->end_controls_section(); } protected function render() { $settings = $this->get_settings_for_display(); // Get strain type $strain = ''; if ($settings['source'] === 'custom') { $strain = $settings['custom_strain']; } else { global $cannaiq_current_product; if (isset($cannaiq_current_product)) { $strain = strtolower($cannaiq_current_product['strainType'] ?? $cannaiq_current_product['strain_type'] ?? ''); } } if (empty($strain)) { return; } // Normalize strain type $strain_key = strtolower($strain); if (!in_array($strain_key, ['sativa', 'indica', 'hybrid'])) { return; } // Format text switch ($settings['text_format']) { case 'uppercase': $text = strtoupper($strain); break; case 'lowercase': $text = strtolower($strain); break; default: $text = ucfirst($strain); } // Get color based on strain type $color = $settings[$strain_key . '_color']; // Build classes $classes = [ 'cannaiq-strain-badge', 'cannaiq-strain-badge--' . $settings['format'], 'cannaiq-strain-badge--' . $strain_key, ]; if ($settings['size'] !== 'medium') { $classes[] = 'cannaiq-strain-badge--' . $settings['size']; } // Build style $style = ''; if ($settings['format'] === 'pill') { $style = sprintf('background-color: %s; color: white;', esc_attr($color)); } else { $style = sprintf('color: %s;', esc_attr($color)); } // Icon SVG (leaf icon) $icon = ''; if ($settings['show_icon'] === 'yes') { $icon = ''; } printf( '%s%s', esc_attr(implode(' ', $classes)), esc_attr($style), $icon, esc_html($text) ); } }