All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
New modular component widgets: - Discount Ribbon (ribbon/pill/text styles) - Strain Badge (Sativa/Indica/Hybrid colored pills) - THC/CBD Meter (progress bars or badges) - Effects Display (styled chips with icons) - Price Block (original + sale price) - Cart Button (styled CTA linking to menu) - Stock Indicator (in/out of stock badges) - Product Image + Badges (image with overlays) New card template: - Premium Product Card (ready-to-use template) Extended dynamic tags (30+ total): - Discount %, Strain Badge, THC/CBD Badge - Effects Chips, Terpenes, Price Display - Menu URL, Stock Status, and more New files: - assets/css/components.css - includes/effects-icons.php (SVG icons) - 10 new widget files - dynamic-tags-extended.php Branding updated to "CannaiQ" throughout. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
289 lines
9.3 KiB
PHP
289 lines
9.3 KiB
PHP
<?php
|
|
/**
|
|
* CannaIQ Effects Display Widget
|
|
*
|
|
* Displays product effects as styled chips with optional icons.
|
|
*
|
|
* @package CannaIQ_Menus
|
|
* @since 2.0.0
|
|
*/
|
|
|
|
if (!defined('ABSPATH')) {
|
|
exit;
|
|
}
|
|
|
|
// Include effects icons helper
|
|
require_once dirname(__DIR__) . '/includes/effects-icons.php';
|
|
|
|
class CannaIQ_Effects_Display_Widget extends \Elementor\Widget_Base {
|
|
|
|
public function get_name() {
|
|
return 'cannaiq_effects_display';
|
|
}
|
|
|
|
public function get_title() {
|
|
return __('Effects Display', 'cannaiq-menus');
|
|
}
|
|
|
|
public function get_icon() {
|
|
return 'eicon-bullet-list';
|
|
}
|
|
|
|
public function get_categories() {
|
|
return ['cannaiq'];
|
|
}
|
|
|
|
public function get_keywords() {
|
|
return ['effects', 'happy', 'relaxed', 'sleepy', 'chips', 'cannaiq'];
|
|
}
|
|
|
|
protected function register_controls() {
|
|
|
|
$this->start_controls_section(
|
|
'content_section',
|
|
[
|
|
'label' => __('Content', 'cannaiq-menus'),
|
|
'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'source',
|
|
[
|
|
'label' => __('Effects Source', 'cannaiq-menus'),
|
|
'type' => \Elementor\Controls_Manager::SELECT,
|
|
'default' => 'auto',
|
|
'options' => [
|
|
'auto' => __('Auto (from product)', 'cannaiq-menus'),
|
|
'custom' => __('Custom values', 'cannaiq-menus'),
|
|
],
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'custom_effects',
|
|
[
|
|
'label' => __('Custom Effects', 'cannaiq-menus'),
|
|
'type' => \Elementor\Controls_Manager::TEXT,
|
|
'default' => 'Happy, Relaxed, Creative',
|
|
'description' => __('Comma-separated list of effects', 'cannaiq-menus'),
|
|
'condition' => [
|
|
'source' => 'custom',
|
|
],
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'limit',
|
|
[
|
|
'label' => __('Max Effects', 'cannaiq-menus'),
|
|
'type' => \Elementor\Controls_Manager::NUMBER,
|
|
'default' => 3,
|
|
'min' => 1,
|
|
'max' => 10,
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'show_icons',
|
|
[
|
|
'label' => __('Show Icons', '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(
|
|
'use_colors',
|
|
[
|
|
'label' => __('Colored Chips', 'cannaiq-menus'),
|
|
'type' => \Elementor\Controls_Manager::SWITCHER,
|
|
'label_on' => __('Yes', 'cannaiq-menus'),
|
|
'label_off' => __('No', 'cannaiq-menus'),
|
|
'return_value' => 'yes',
|
|
'default' => 'yes',
|
|
'description' => __('Use effect-specific colors', 'cannaiq-menus'),
|
|
]
|
|
);
|
|
|
|
$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(
|
|
'gap',
|
|
[
|
|
'label' => __('Gap', 'cannaiq-menus'),
|
|
'type' => \Elementor\Controls_Manager::SLIDER,
|
|
'size_units' => ['px'],
|
|
'range' => [
|
|
'px' => [
|
|
'min' => 2,
|
|
'max' => 20,
|
|
],
|
|
],
|
|
'default' => [
|
|
'size' => 8,
|
|
],
|
|
'selectors' => [
|
|
'{{WRAPPER}} .cannaiq-effects-container' => 'gap: {{SIZE}}{{UNIT}};',
|
|
],
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'default_background',
|
|
[
|
|
'label' => __('Default Background', 'cannaiq-menus'),
|
|
'type' => \Elementor\Controls_Manager::COLOR,
|
|
'default' => '#f3f4f6',
|
|
'condition' => [
|
|
'use_colors!' => 'yes',
|
|
],
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'text_color',
|
|
[
|
|
'label' => __('Text Color', 'cannaiq-menus'),
|
|
'type' => \Elementor\Controls_Manager::COLOR,
|
|
'default' => '#1f2937',
|
|
'selectors' => [
|
|
'{{WRAPPER}} .cannaiq-effect-chip' => 'color: {{VALUE}};',
|
|
],
|
|
]
|
|
);
|
|
|
|
$this->add_group_control(
|
|
\Elementor\Group_Control_Typography::get_type(),
|
|
[
|
|
'name' => 'typography',
|
|
'selector' => '{{WRAPPER}} .cannaiq-effect-chip',
|
|
]
|
|
);
|
|
|
|
$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' => 999,
|
|
],
|
|
'selectors' => [
|
|
'{{WRAPPER}} .cannaiq-effect-chip' => 'border-radius: {{SIZE}}{{UNIT}};',
|
|
],
|
|
]
|
|
);
|
|
|
|
$this->end_controls_section();
|
|
}
|
|
|
|
protected function render() {
|
|
$settings = $this->get_settings_for_display();
|
|
|
|
// Get effects
|
|
$effects = [];
|
|
if ($settings['source'] === 'custom') {
|
|
$effects_string = $settings['custom_effects'];
|
|
$effects = array_map('trim', explode(',', $effects_string));
|
|
} else {
|
|
global $cannaiq_current_product;
|
|
if (isset($cannaiq_current_product)) {
|
|
$raw_effects = $cannaiq_current_product['effects'] ?? [];
|
|
if (is_array($raw_effects)) {
|
|
// If effects is associative array with scores, sort by score
|
|
if (isset($raw_effects[0]) && !is_array($raw_effects[0])) {
|
|
$effects = $raw_effects;
|
|
} else {
|
|
// Sort by value descending and get keys
|
|
arsort($raw_effects);
|
|
$effects = array_keys($raw_effects);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (empty($effects)) {
|
|
return;
|
|
}
|
|
|
|
// Apply limit
|
|
$limit = intval($settings['limit']);
|
|
$effects = array_slice($effects, 0, $limit);
|
|
|
|
// Determine icon size
|
|
$icon_size = $settings['size'] === 'small' ? 12 : ($settings['size'] === 'large' ? 20 : 16);
|
|
?>
|
|
<div class="cannaiq-effects-container">
|
|
<?php foreach ($effects as $effect): ?>
|
|
<?php
|
|
$effect_name = ucfirst(strtolower(trim($effect)));
|
|
$effect_key = strtolower(trim($effect));
|
|
|
|
// Get color if using colors
|
|
$color = '#6B7280'; // Default gray
|
|
$style = '';
|
|
if ($settings['use_colors'] === 'yes') {
|
|
$color = cannaiq_get_effect_color($effect);
|
|
$style = sprintf('--effect-color: %s;', esc_attr($color));
|
|
} else {
|
|
$style = sprintf('background: %s; border-color: %s;',
|
|
esc_attr($settings['default_background']),
|
|
esc_attr($settings['default_background'])
|
|
);
|
|
}
|
|
|
|
// Build classes
|
|
$classes = ['cannaiq-effect-chip'];
|
|
if ($settings['size'] !== 'medium') {
|
|
$classes[] = 'cannaiq-effect-chip--' . $settings['size'];
|
|
}
|
|
?>
|
|
<span class="<?php echo esc_attr(implode(' ', $classes)); ?>" style="<?php echo esc_attr($style); ?>">
|
|
<?php if ($settings['show_icons'] === 'yes'): ?>
|
|
<?php echo cannaiq_get_effect_icon($effect, [
|
|
'size' => $icon_size,
|
|
'color' => $settings['use_colors'] === 'yes' ? $color : 'currentColor',
|
|
]); ?>
|
|
<?php endif; ?>
|
|
<span class="cannaiq-effect-chip__label"><?php echo esc_html($effect_name); ?></span>
|
|
</span>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<?php
|
|
}
|
|
}
|