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>
217 lines
6.5 KiB
PHP
217 lines
6.5 KiB
PHP
<?php
|
|
/**
|
|
* CannaIQ Discount Ribbon Widget
|
|
*
|
|
* Displays discount percentage as a positioned badge/ribbon.
|
|
*
|
|
* @package CannaIQ_Menus
|
|
* @since 2.0.0
|
|
*/
|
|
|
|
if (!defined('ABSPATH')) {
|
|
exit;
|
|
}
|
|
|
|
class CannaIQ_Discount_Ribbon_Widget extends \Elementor\Widget_Base {
|
|
|
|
public function get_name() {
|
|
return 'cannaiq_discount_ribbon';
|
|
}
|
|
|
|
public function get_title() {
|
|
return __('Discount Ribbon', 'cannaiq-menus');
|
|
}
|
|
|
|
public function get_icon() {
|
|
return 'eicon-price-table';
|
|
}
|
|
|
|
public function get_categories() {
|
|
return ['cannaiq'];
|
|
}
|
|
|
|
public function get_keywords() {
|
|
return ['discount', 'sale', 'ribbon', 'badge', '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' => __('Discount 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_discount',
|
|
[
|
|
'label' => __('Discount Percentage', 'cannaiq-menus'),
|
|
'type' => \Elementor\Controls_Manager::NUMBER,
|
|
'default' => 25,
|
|
'min' => 1,
|
|
'max' => 99,
|
|
'condition' => [
|
|
'source' => 'custom',
|
|
],
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'format',
|
|
[
|
|
'label' => __('Display Format', 'cannaiq-menus'),
|
|
'type' => \Elementor\Controls_Manager::SELECT,
|
|
'default' => 'ribbon',
|
|
'options' => [
|
|
'ribbon' => __('Ribbon', 'cannaiq-menus'),
|
|
'pill' => __('Pill', 'cannaiq-menus'),
|
|
'text' => __('Text Only', 'cannaiq-menus'),
|
|
],
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'text_template',
|
|
[
|
|
'label' => __('Text Template', 'cannaiq-menus'),
|
|
'type' => \Elementor\Controls_Manager::TEXT,
|
|
'default' => '{percent}% OFF',
|
|
'description' => __('Use {percent} as placeholder', 'cannaiq-menus'),
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'hide_if_no_discount',
|
|
[
|
|
'label' => __('Hide if No Discount', 'cannaiq-menus'),
|
|
'type' => \Elementor\Controls_Manager::SWITCHER,
|
|
'label_on' => __('Yes', 'cannaiq-menus'),
|
|
'label_off' => __('No', 'cannaiq-menus'),
|
|
'return_value' => 'yes',
|
|
'default' => '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(
|
|
'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(
|
|
'background_color',
|
|
[
|
|
'label' => __('Background Color', 'cannaiq-menus'),
|
|
'type' => \Elementor\Controls_Manager::COLOR,
|
|
'default' => '#ef4444',
|
|
'selectors' => [
|
|
'{{WRAPPER}} .cannaiq-discount-ribbon' => 'background-color: {{VALUE}};',
|
|
],
|
|
'condition' => [
|
|
'format!' => 'text',
|
|
],
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'text_color',
|
|
[
|
|
'label' => __('Text Color', 'cannaiq-menus'),
|
|
'type' => \Elementor\Controls_Manager::COLOR,
|
|
'default' => '#ffffff',
|
|
'selectors' => [
|
|
'{{WRAPPER}} .cannaiq-discount-ribbon' => 'color: {{VALUE}};',
|
|
],
|
|
]
|
|
);
|
|
|
|
$this->add_group_control(
|
|
\Elementor\Group_Control_Typography::get_type(),
|
|
[
|
|
'name' => 'typography',
|
|
'selector' => '{{WRAPPER}} .cannaiq-discount-ribbon',
|
|
]
|
|
);
|
|
|
|
$this->end_controls_section();
|
|
}
|
|
|
|
protected function render() {
|
|
$settings = $this->get_settings_for_display();
|
|
|
|
// Get discount percentage
|
|
$discount = 0;
|
|
if ($settings['source'] === 'custom') {
|
|
$discount = intval($settings['custom_discount']);
|
|
} else {
|
|
// Get from product context
|
|
global $cannaiq_current_product;
|
|
if (isset($cannaiq_current_product)) {
|
|
$original = $cannaiq_current_product['Prices'][0] ?? $cannaiq_current_product['regular_price'] ?? null;
|
|
$sale = $cannaiq_current_product['specialPrice'] ?? $cannaiq_current_product['sale_price'] ?? null;
|
|
|
|
if ($original && $sale && $original > $sale) {
|
|
$discount = round((($original - $sale) / $original) * 100);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Hide if no discount and setting enabled
|
|
if ($discount <= 0 && $settings['hide_if_no_discount'] === 'yes') {
|
|
return;
|
|
}
|
|
|
|
// Build display text
|
|
$text = str_replace('{percent}', $discount, $settings['text_template']);
|
|
|
|
// Build classes
|
|
$classes = [
|
|
'cannaiq-discount-ribbon',
|
|
'cannaiq-discount-ribbon--' . $settings['format'],
|
|
];
|
|
if ($settings['size'] !== 'medium') {
|
|
$classes[] = 'cannaiq-discount-ribbon--' . $settings['size'];
|
|
}
|
|
|
|
printf(
|
|
'<span class="%s">%s</span>',
|
|
esc_attr(implode(' ', $classes)),
|
|
esc_html($text)
|
|
);
|
|
}
|
|
}
|