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>
259 lines
8.0 KiB
PHP
259 lines
8.0 KiB
PHP
<?php
|
|
/**
|
|
* CannaIQ Stock Indicator Widget
|
|
*
|
|
* Displays product stock status (In Stock / Out of Stock).
|
|
*
|
|
* @package CannaIQ_Menus
|
|
* @since 2.0.0
|
|
*/
|
|
|
|
if (!defined('ABSPATH')) {
|
|
exit;
|
|
}
|
|
|
|
class CannaIQ_Stock_Indicator_Widget extends \Elementor\Widget_Base {
|
|
|
|
public function get_name() {
|
|
return 'cannaiq_stock_indicator';
|
|
}
|
|
|
|
public function get_title() {
|
|
return __('Stock Indicator', 'cannaiq-menus');
|
|
}
|
|
|
|
public function get_icon() {
|
|
return 'eicon-check-circle';
|
|
}
|
|
|
|
public function get_categories() {
|
|
return ['cannaiq'];
|
|
}
|
|
|
|
public function get_keywords() {
|
|
return ['stock', 'inventory', 'available', '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' => __('Stock 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_in_stock',
|
|
[
|
|
'label' => __('In Stock', 'cannaiq-menus'),
|
|
'type' => \Elementor\Controls_Manager::SWITCHER,
|
|
'label_on' => __('Yes', 'cannaiq-menus'),
|
|
'label_off' => __('No', 'cannaiq-menus'),
|
|
'return_value' => 'yes',
|
|
'default' => 'yes',
|
|
'condition' => [
|
|
'source' => 'custom',
|
|
],
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'format',
|
|
[
|
|
'label' => __('Display Format', 'cannaiq-menus'),
|
|
'type' => \Elementor\Controls_Manager::SELECT,
|
|
'default' => 'badge',
|
|
'options' => [
|
|
'badge' => __('Badge', 'cannaiq-menus'),
|
|
'text' => __('Text', 'cannaiq-menus'),
|
|
'dot' => __('Dot + Text', 'cannaiq-menus'),
|
|
],
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'in_stock_text',
|
|
[
|
|
'label' => __('In Stock Text', 'cannaiq-menus'),
|
|
'type' => \Elementor\Controls_Manager::TEXT,
|
|
'default' => 'In Stock',
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'out_of_stock_text',
|
|
[
|
|
'label' => __('Out of Stock Text', 'cannaiq-menus'),
|
|
'type' => \Elementor\Controls_Manager::TEXT,
|
|
'default' => 'Out of Stock',
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'show_quantity',
|
|
[
|
|
'label' => __('Show Quantity', 'cannaiq-menus'),
|
|
'type' => \Elementor\Controls_Manager::SWITCHER,
|
|
'label_on' => __('Yes', 'cannaiq-menus'),
|
|
'label_off' => __('No', 'cannaiq-menus'),
|
|
'return_value' => 'yes',
|
|
'default' => '',
|
|
'description' => __('Show quantity if available', 'cannaiq-menus'),
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'hide_if_in_stock',
|
|
[
|
|
'label' => __('Hide if In Stock', 'cannaiq-menus'),
|
|
'type' => \Elementor\Controls_Manager::SWITCHER,
|
|
'label_on' => __('Yes', 'cannaiq-menus'),
|
|
'label_off' => __('No', 'cannaiq-menus'),
|
|
'return_value' => 'yes',
|
|
'default' => '',
|
|
'description' => __('Only show when out of stock', '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(
|
|
'in_stock_color',
|
|
[
|
|
'label' => __('In Stock Color', 'cannaiq-menus'),
|
|
'type' => \Elementor\Controls_Manager::COLOR,
|
|
'default' => '#16a34a',
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'out_of_stock_color',
|
|
[
|
|
'label' => __('Out of Stock Color', 'cannaiq-menus'),
|
|
'type' => \Elementor\Controls_Manager::COLOR,
|
|
'default' => '#9ca3af',
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'in_stock_bg',
|
|
[
|
|
'label' => __('In Stock Background', 'cannaiq-menus'),
|
|
'type' => \Elementor\Controls_Manager::COLOR,
|
|
'default' => '#dcfce7',
|
|
'condition' => [
|
|
'format' => 'badge',
|
|
],
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'out_of_stock_bg',
|
|
[
|
|
'label' => __('Out of Stock Background', 'cannaiq-menus'),
|
|
'type' => \Elementor\Controls_Manager::COLOR,
|
|
'default' => '#f3f4f6',
|
|
'condition' => [
|
|
'format' => 'badge',
|
|
],
|
|
]
|
|
);
|
|
|
|
$this->add_group_control(
|
|
\Elementor\Group_Control_Typography::get_type(),
|
|
[
|
|
'name' => 'typography',
|
|
'selector' => '{{WRAPPER}} .cannaiq-stock-indicator',
|
|
]
|
|
);
|
|
|
|
$this->end_controls_section();
|
|
}
|
|
|
|
protected function render() {
|
|
$settings = $this->get_settings_for_display();
|
|
|
|
// Get stock status
|
|
$in_stock = true;
|
|
$quantity = null;
|
|
|
|
if ($settings['source'] === 'custom') {
|
|
$in_stock = $settings['custom_in_stock'] === 'yes';
|
|
} else {
|
|
global $cannaiq_current_product;
|
|
if (isset($cannaiq_current_product)) {
|
|
$status = $cannaiq_current_product['Status'] ?? '';
|
|
$in_stock = ($status === 'Active' || $status === 'In Stock' || !empty($cannaiq_current_product['in_stock']));
|
|
|
|
// Get quantity if available
|
|
$quantity = $cannaiq_current_product['POSMetaData']['children'][0]['quantity']
|
|
?? $cannaiq_current_product['quantity']
|
|
?? null;
|
|
}
|
|
}
|
|
|
|
// Hide if in stock and setting enabled
|
|
if ($in_stock && $settings['hide_if_in_stock'] === 'yes') {
|
|
return;
|
|
}
|
|
|
|
// Determine display text
|
|
$text = $in_stock ? $settings['in_stock_text'] : $settings['out_of_stock_text'];
|
|
if ($in_stock && $settings['show_quantity'] === 'yes' && $quantity !== null) {
|
|
$text .= ' (' . intval($quantity) . ')';
|
|
}
|
|
|
|
// Colors
|
|
$color = $in_stock ? $settings['in_stock_color'] : $settings['out_of_stock_color'];
|
|
$bg_color = $in_stock ? $settings['in_stock_bg'] : $settings['out_of_stock_bg'];
|
|
|
|
// Build classes
|
|
$classes = [
|
|
'cannaiq-stock-indicator',
|
|
$in_stock ? 'cannaiq-stock-indicator--in-stock' : 'cannaiq-stock-indicator--out-of-stock',
|
|
];
|
|
if ($settings['format'] === 'badge') {
|
|
$classes[] = 'cannaiq-stock-indicator--badge';
|
|
}
|
|
|
|
// Build style
|
|
$style = sprintf('color: %s;', esc_attr($color));
|
|
if ($settings['format'] === 'badge') {
|
|
$style .= sprintf(' background-color: %s;', esc_attr($bg_color));
|
|
}
|
|
|
|
?>
|
|
<span class="<?php echo esc_attr(implode(' ', $classes)); ?>" style="<?php echo esc_attr($style); ?>">
|
|
<?php if ($settings['format'] === 'dot'): ?>
|
|
<span class="cannaiq-stock-indicator__dot"></span>
|
|
<?php endif; ?>
|
|
<?php echo esc_html($text); ?>
|
|
</span>
|
|
<?php
|
|
}
|
|
}
|