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>
296 lines
9.8 KiB
PHP
296 lines
9.8 KiB
PHP
<?php
|
|
/**
|
|
* CannaIQ THC/CBD Meter Widget
|
|
*
|
|
* Displays THC or CBD percentage as a visual meter/progress bar.
|
|
*
|
|
* @package CannaIQ_Menus
|
|
* @since 2.0.0
|
|
*/
|
|
|
|
if (!defined('ABSPATH')) {
|
|
exit;
|
|
}
|
|
|
|
class CannaIQ_THC_Meter_Widget extends \Elementor\Widget_Base {
|
|
|
|
public function get_name() {
|
|
return 'cannaiq_thc_meter';
|
|
}
|
|
|
|
public function get_title() {
|
|
return __('THC/CBD Meter', 'cannaiq-menus');
|
|
}
|
|
|
|
public function get_icon() {
|
|
return 'eicon-skill-bar';
|
|
}
|
|
|
|
public function get_categories() {
|
|
return ['cannaiq'];
|
|
}
|
|
|
|
public function get_keywords() {
|
|
return ['thc', 'cbd', 'potency', 'meter', 'percentage', 'cannaiq'];
|
|
}
|
|
|
|
protected function register_controls() {
|
|
|
|
$this->start_controls_section(
|
|
'content_section',
|
|
[
|
|
'label' => __('Content', 'cannaiq-menus'),
|
|
'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'type',
|
|
[
|
|
'label' => __('Type', 'cannaiq-menus'),
|
|
'type' => \Elementor\Controls_Manager::SELECT,
|
|
'default' => 'thc',
|
|
'options' => [
|
|
'thc' => __('THC', 'cannaiq-menus'),
|
|
'cbd' => __('CBD', 'cannaiq-menus'),
|
|
],
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'source',
|
|
[
|
|
'label' => __('Value 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_value',
|
|
[
|
|
'label' => __('Percentage', 'cannaiq-menus'),
|
|
'type' => \Elementor\Controls_Manager::NUMBER,
|
|
'default' => 20,
|
|
'min' => 0,
|
|
'max' => 100,
|
|
'step' => 0.1,
|
|
'condition' => [
|
|
'source' => 'custom',
|
|
],
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'display_format',
|
|
[
|
|
'label' => __('Display Format', 'cannaiq-menus'),
|
|
'type' => \Elementor\Controls_Manager::SELECT,
|
|
'default' => 'meter',
|
|
'options' => [
|
|
'meter' => __('Meter (progress bar)', 'cannaiq-menus'),
|
|
'badge' => __('Badge', 'cannaiq-menus'),
|
|
'pill' => __('Pill', 'cannaiq-menus'),
|
|
'text' => __('Text Only', 'cannaiq-menus'),
|
|
],
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'show_label',
|
|
[
|
|
'label' => __('Show Label', '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(
|
|
'max_percentage',
|
|
[
|
|
'label' => __('Max Percentage (for meter)', 'cannaiq-menus'),
|
|
'type' => \Elementor\Controls_Manager::NUMBER,
|
|
'default' => 35,
|
|
'min' => 10,
|
|
'max' => 100,
|
|
'description' => __('Used to calculate bar fill percentage', 'cannaiq-menus'),
|
|
'condition' => [
|
|
'display_format' => 'meter',
|
|
],
|
|
]
|
|
);
|
|
|
|
$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(
|
|
'thc_color',
|
|
[
|
|
'label' => __('THC Color', 'cannaiq-menus'),
|
|
'type' => \Elementor\Controls_Manager::COLOR,
|
|
'default' => '#22c55e',
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'cbd_color',
|
|
[
|
|
'label' => __('CBD Color', 'cannaiq-menus'),
|
|
'type' => \Elementor\Controls_Manager::COLOR,
|
|
'default' => '#3b82f6',
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'bar_height',
|
|
[
|
|
'label' => __('Bar Height', 'cannaiq-menus'),
|
|
'type' => \Elementor\Controls_Manager::SLIDER,
|
|
'size_units' => ['px'],
|
|
'range' => [
|
|
'px' => [
|
|
'min' => 4,
|
|
'max' => 20,
|
|
],
|
|
],
|
|
'default' => [
|
|
'size' => 6,
|
|
],
|
|
'selectors' => [
|
|
'{{WRAPPER}} .cannaiq-potency-meter__bar' => 'height: {{SIZE}}{{UNIT}};',
|
|
],
|
|
'condition' => [
|
|
'display_format' => 'meter',
|
|
],
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'bar_background',
|
|
[
|
|
'label' => __('Bar Background', 'cannaiq-menus'),
|
|
'type' => \Elementor\Controls_Manager::COLOR,
|
|
'default' => '#e5e7eb',
|
|
'selectors' => [
|
|
'{{WRAPPER}} .cannaiq-potency-meter__bar' => 'background-color: {{VALUE}};',
|
|
],
|
|
'condition' => [
|
|
'display_format' => 'meter',
|
|
],
|
|
]
|
|
);
|
|
|
|
$this->add_group_control(
|
|
\Elementor\Group_Control_Typography::get_type(),
|
|
[
|
|
'name' => 'typography',
|
|
'selector' => '{{WRAPPER}} .cannaiq-potency-meter, {{WRAPPER}} .cannaiq-potency-badge',
|
|
]
|
|
);
|
|
|
|
$this->end_controls_section();
|
|
}
|
|
|
|
protected function render() {
|
|
$settings = $this->get_settings_for_display();
|
|
$type = $settings['type'];
|
|
|
|
// Get percentage value
|
|
$percentage = 0;
|
|
if ($settings['source'] === 'custom') {
|
|
$percentage = floatval($settings['custom_value']);
|
|
} else {
|
|
global $cannaiq_current_product;
|
|
if (isset($cannaiq_current_product)) {
|
|
if ($type === 'thc') {
|
|
$percentage = $cannaiq_current_product['THCContent']['range'][0]
|
|
?? $cannaiq_current_product['THC']
|
|
?? $cannaiq_current_product['thc_percentage']
|
|
?? 0;
|
|
} else {
|
|
$percentage = $cannaiq_current_product['CBDContent']['range'][0]
|
|
?? $cannaiq_current_product['CBD']
|
|
?? $cannaiq_current_product['cbd_percentage']
|
|
?? 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
$percentage = floatval($percentage);
|
|
if ($percentage <= 0) {
|
|
return;
|
|
}
|
|
|
|
$label = strtoupper($type);
|
|
$color = $type === 'thc' ? $settings['thc_color'] : $settings['cbd_color'];
|
|
$formatted_value = number_format($percentage, 1) . '%';
|
|
|
|
switch ($settings['display_format']) {
|
|
case 'meter':
|
|
$fill_percent = min(100, ($percentage / floatval($settings['max_percentage'])) * 100);
|
|
?>
|
|
<div class="cannaiq-potency-meter cannaiq-potency-meter--<?php echo esc_attr($type); ?>">
|
|
<?php if ($settings['show_label'] === 'yes'): ?>
|
|
<div class="cannaiq-potency-meter__header">
|
|
<span class="cannaiq-potency-meter__label"><?php echo esc_html($label); ?></span>
|
|
<span class="cannaiq-potency-meter__value"><?php echo esc_html($formatted_value); ?></span>
|
|
</div>
|
|
<?php endif; ?>
|
|
<div class="cannaiq-potency-meter__bar">
|
|
<div class="cannaiq-potency-meter__fill" style="width: <?php echo esc_attr($fill_percent); ?>%; background: linear-gradient(90deg, <?php echo esc_attr($color); ?> 0%, <?php echo esc_attr($color); ?> 100%);"></div>
|
|
</div>
|
|
</div>
|
|
<?php
|
|
break;
|
|
|
|
case 'badge':
|
|
?>
|
|
<span class="cannaiq-potency-badge cannaiq-potency-badge--badge">
|
|
<?php if ($settings['show_label'] === 'yes'): ?>
|
|
<span class="cannaiq-potency-badge__label"><?php echo esc_html($label); ?></span>
|
|
<?php endif; ?>
|
|
<span class="cannaiq-potency-badge__value"><?php echo esc_html($formatted_value); ?></span>
|
|
</span>
|
|
<?php
|
|
break;
|
|
|
|
case 'pill':
|
|
?>
|
|
<span class="cannaiq-potency-badge cannaiq-potency-badge--pill" style="background-color: <?php echo esc_attr($color); ?>;">
|
|
<?php if ($settings['show_label'] === 'yes'): ?>
|
|
<?php echo esc_html($label); ?>:
|
|
<?php endif; ?>
|
|
<?php echo esc_html($formatted_value); ?>
|
|
</span>
|
|
<?php
|
|
break;
|
|
|
|
case 'text':
|
|
?>
|
|
<span class="cannaiq-potency-badge cannaiq-potency-badge--text">
|
|
<?php if ($settings['show_label'] === 'yes'): ?>
|
|
<?php echo esc_html($label); ?>:
|
|
<?php endif; ?>
|
|
<?php echo esc_html($formatted_value); ?>
|
|
</span>
|
|
<?php
|
|
break;
|
|
}
|
|
}
|
|
}
|