start_controls_section( 'content_section', [ 'label' => __('Image', 'cannaiq-menus'), 'tab' => \Elementor\Controls_Manager::TAB_CONTENT, ] ); $this->add_control( 'image_source', [ 'label' => __('Image Source', 'cannaiq-menus'), 'type' => \Elementor\Controls_Manager::SELECT, 'default' => 'auto', 'options' => [ 'auto' => __('Auto (from product)', 'cannaiq-menus'), 'custom' => __('Custom image', 'cannaiq-menus'), ], ] ); $this->add_control( 'custom_image', [ 'label' => __('Choose Image', 'cannaiq-menus'), 'type' => \Elementor\Controls_Manager::MEDIA, 'default' => [ 'url' => \Elementor\Utils::get_placeholder_image_src(), ], 'condition' => [ 'image_source' => 'custom', ], ] ); $this->add_control( 'fallback_image', [ 'label' => __('Fallback Image', 'cannaiq-menus'), 'type' => \Elementor\Controls_Manager::MEDIA, 'description' => __('Shown if product has no image', 'cannaiq-menus'), ] ); $this->add_control( 'aspect_ratio', [ 'label' => __('Aspect Ratio', 'cannaiq-menus'), 'type' => \Elementor\Controls_Manager::SELECT, 'default' => '1/1', 'options' => [ '1/1' => __('Square (1:1)', 'cannaiq-menus'), '4/3' => __('4:3', 'cannaiq-menus'), '3/4' => __('3:4', 'cannaiq-menus'), '16/9' => __('16:9', 'cannaiq-menus'), 'auto' => __('Auto', 'cannaiq-menus'), ], ] ); $this->add_control( 'hover_effect', [ 'label' => __('Hover Effect', 'cannaiq-menus'), 'type' => \Elementor\Controls_Manager::SELECT, 'default' => 'zoom', 'options' => [ 'none' => __('None', 'cannaiq-menus'), 'zoom' => __('Zoom', 'cannaiq-menus'), ], ] ); $this->end_controls_section(); // Overlay Badges Section $this->start_controls_section( 'overlays_section', [ 'label' => __('Badge Overlays', 'cannaiq-menus'), 'tab' => \Elementor\Controls_Manager::TAB_CONTENT, ] ); $this->add_control( 'show_discount_badge', [ 'label' => __('Show Discount Badge', 'cannaiq-menus'), 'type' => \Elementor\Controls_Manager::SWITCHER, 'label_on' => __('Yes', 'cannaiq-menus'), 'label_off' => __('No', 'cannaiq-menus'), 'return_value' => 'yes', 'default' => 'yes', ] ); $this->add_control( 'discount_position', [ 'label' => __('Discount Position', 'cannaiq-menus'), 'type' => \Elementor\Controls_Manager::SELECT, 'default' => 'top-left', 'options' => [ 'top-left' => __('Top Left', 'cannaiq-menus'), 'top-right' => __('Top Right', 'cannaiq-menus'), 'bottom-left' => __('Bottom Left', 'cannaiq-menus'), 'bottom-right' => __('Bottom Right', 'cannaiq-menus'), ], 'condition' => [ 'show_discount_badge' => 'yes', ], ] ); $this->add_control( 'show_strain_badge', [ 'label' => __('Show Strain Badge', 'cannaiq-menus'), 'type' => \Elementor\Controls_Manager::SWITCHER, 'label_on' => __('Yes', 'cannaiq-menus'), 'label_off' => __('No', 'cannaiq-menus'), 'return_value' => 'yes', 'default' => 'yes', ] ); $this->add_control( 'strain_position', [ 'label' => __('Strain Position', 'cannaiq-menus'), 'type' => \Elementor\Controls_Manager::SELECT, 'default' => 'bottom-left', 'options' => [ 'top-left' => __('Top Left', 'cannaiq-menus'), 'top-right' => __('Top Right', 'cannaiq-menus'), 'bottom-left' => __('Bottom Left', 'cannaiq-menus'), 'bottom-right' => __('Bottom Right', 'cannaiq-menus'), ], 'condition' => [ 'show_strain_badge' => 'yes', ], ] ); $this->add_control( 'show_thc_badge', [ 'label' => __('Show THC Badge', 'cannaiq-menus'), 'type' => \Elementor\Controls_Manager::SWITCHER, 'label_on' => __('Yes', 'cannaiq-menus'), 'label_off' => __('No', 'cannaiq-menus'), 'return_value' => 'yes', 'default' => '', ] ); $this->add_control( 'thc_position', [ 'label' => __('THC Position', 'cannaiq-menus'), 'type' => \Elementor\Controls_Manager::SELECT, 'default' => 'bottom-right', 'options' => [ 'top-left' => __('Top Left', 'cannaiq-menus'), 'top-right' => __('Top Right', 'cannaiq-menus'), 'bottom-left' => __('Bottom Left', 'cannaiq-menus'), 'bottom-right' => __('Bottom Right', 'cannaiq-menus'), ], 'condition' => [ 'show_thc_badge' => 'yes', ], ] ); $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( 'border_radius', [ 'label' => __('Border Radius', 'cannaiq-menus'), 'type' => \Elementor\Controls_Manager::SLIDER, 'size_units' => ['px'], 'range' => [ 'px' => [ 'min' => 0, 'max' => 50, ], ], 'default' => [ 'size' => 8, ], 'selectors' => [ '{{WRAPPER}} .cannaiq-product-image' => 'border-radius: {{SIZE}}{{UNIT}};', ], ] ); $this->add_control( 'background_color', [ 'label' => __('Background Color', 'cannaiq-menus'), 'type' => \Elementor\Controls_Manager::COLOR, 'default' => '#f9fafb', 'selectors' => [ '{{WRAPPER}} .cannaiq-product-image' => 'background-color: {{VALUE}};', ], ] ); $this->add_group_control( \Elementor\Group_Control_Box_Shadow::get_type(), [ 'name' => 'box_shadow', 'selector' => '{{WRAPPER}} .cannaiq-product-image', ] ); $this->end_controls_section(); } protected function render() { $settings = $this->get_settings_for_display(); // Get image URL $image_url = ''; if ($settings['image_source'] === 'custom') { $image_url = $settings['custom_image']['url'] ?? ''; } else { global $cannaiq_current_product; if (isset($cannaiq_current_product)) { $image_url = $cannaiq_current_product['Image'] ?? $cannaiq_current_product['images'][0]['url'] ?? $cannaiq_current_product['image_url'] ?? ''; } } // Use fallback if no image if (empty($image_url) && !empty($settings['fallback_image']['url'])) { $image_url = $settings['fallback_image']['url']; } // Get product name for alt text $alt_text = ''; global $cannaiq_current_product; if (isset($cannaiq_current_product)) { $alt_text = $cannaiq_current_product['Name'] ?? $cannaiq_current_product['name'] ?? ''; } // Aspect ratio style $aspect_style = ''; if ($settings['aspect_ratio'] !== 'auto') { $aspect_style = 'aspect-ratio: ' . $settings['aspect_ratio'] . ';'; } // Hover class $hover_class = $settings['hover_effect'] === 'zoom' ? 'cannaiq-product-image--hover-zoom' : ''; // Group badges by position $badges_by_position = []; if ($settings['show_discount_badge'] === 'yes') { $badges_by_position[$settings['discount_position']][] = 'discount'; } if ($settings['show_strain_badge'] === 'yes') { $badges_by_position[$settings['strain_position']][] = 'strain'; } if ($settings['show_thc_badge'] === 'yes') { $badges_by_position[$settings['thc_position']][] = 'thc'; } ?>
<?php echo esc_attr($alt_text); ?> $badges): ?>
render_badge($badge_type); ?>
$sale) { $percent = round((($original - $sale) / $original) * 100); echo '' . esc_html($percent) . '% OFF'; } break; case 'strain': if (!isset($cannaiq_current_product)) return; $strain = strtolower($cannaiq_current_product['strainType'] ?? $cannaiq_current_product['strain_type'] ?? ''); if (!empty($strain) && in_array($strain, ['sativa', 'indica', 'hybrid'])) { $colors = [ 'sativa' => '#22c55e', 'indica' => '#8b5cf6', 'hybrid' => '#f97316', ]; $color = $colors[$strain]; echo '' . esc_html(strtoupper($strain)) . ''; } break; case 'thc': if (!isset($cannaiq_current_product)) return; $thc = $cannaiq_current_product['THCContent']['range'][0] ?? $cannaiq_current_product['THC'] ?? $cannaiq_current_product['thc_percentage'] ?? null; if ($thc !== null && $thc > 0) { echo '' . esc_html(number_format((float)$thc, 1)) . '% THC'; } break; } } }