Files
cannaiq/wordpress-plugin/widgets/cart-button.php
Kelly c33ed1cae9
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
feat: CannaiQ Menus WordPress Plugin v2.0.0 - Modular Component Library
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>
2025-12-17 00:21:40 -07:00

304 lines
9.7 KiB
PHP

<?php
/**
* CannaIQ Cart Button Widget
*
* Displays a styled "Add to Cart" button that links to the menu/dispensary.
*
* @package CannaIQ_Menus
* @since 2.0.0
*/
if (!defined('ABSPATH')) {
exit;
}
class CannaIQ_Cart_Button_Widget extends \Elementor\Widget_Base {
public function get_name() {
return 'cannaiq_cart_button';
}
public function get_title() {
return __('Cart Button', 'cannaiq-menus');
}
public function get_icon() {
return 'eicon-cart';
}
public function get_categories() {
return ['cannaiq'];
}
public function get_keywords() {
return ['cart', 'buy', 'order', 'shop', 'button', 'cannaiq'];
}
protected function register_controls() {
$this->start_controls_section(
'content_section',
[
'label' => __('Content', 'cannaiq-menus'),
'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
]
);
$this->add_control(
'button_text',
[
'label' => __('Button Text', 'cannaiq-menus'),
'type' => \Elementor\Controls_Manager::TEXT,
'default' => 'ADD TO CART',
]
);
$this->add_control(
'link_source',
[
'label' => __('Link Source', 'cannaiq-menus'),
'type' => \Elementor\Controls_Manager::SELECT,
'default' => 'auto',
'options' => [
'auto' => __('Auto (from product)', 'cannaiq-menus'),
'custom' => __('Custom URL', 'cannaiq-menus'),
],
]
);
$this->add_control(
'custom_url',
[
'label' => __('Custom URL', 'cannaiq-menus'),
'type' => \Elementor\Controls_Manager::URL,
'placeholder' => 'https://dutchie.com/store/...',
'condition' => [
'link_source' => 'custom',
],
]
);
$this->add_control(
'open_in_new_tab',
[
'label' => __('Open in New Tab', '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(
'show_icon',
[
'label' => __('Show Icon', 'cannaiq-menus'),
'type' => \Elementor\Controls_Manager::SWITCHER,
'label_on' => __('Yes', 'cannaiq-menus'),
'label_off' => __('No', 'cannaiq-menus'),
'return_value' => 'yes',
'default' => '',
]
);
$this->add_control(
'icon_position',
[
'label' => __('Icon Position', 'cannaiq-menus'),
'type' => \Elementor\Controls_Manager::SELECT,
'default' => 'after',
'options' => [
'before' => __('Before Text', 'cannaiq-menus'),
'after' => __('After Text', 'cannaiq-menus'),
],
'condition' => [
'show_icon' => '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(
'button_style',
[
'label' => __('Button Style', 'cannaiq-menus'),
'type' => \Elementor\Controls_Manager::SELECT,
'default' => 'solid',
'options' => [
'solid' => __('Solid', 'cannaiq-menus'),
'outline' => __('Outline', 'cannaiq-menus'),
],
]
);
$this->add_control(
'full_width',
[
'label' => __('Full Width', 'cannaiq-menus'),
'type' => \Elementor\Controls_Manager::SWITCHER,
'label_on' => __('Yes', 'cannaiq-menus'),
'label_off' => __('No', 'cannaiq-menus'),
'return_value' => 'yes',
'default' => '',
]
);
$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' => '#1f2937',
'selectors' => [
'{{WRAPPER}} .cannaiq-cart-button--solid' => 'background-color: {{VALUE}}; border-color: {{VALUE}};',
'{{WRAPPER}} .cannaiq-cart-button--outline' => 'border-color: {{VALUE}};',
'{{WRAPPER}} .cannaiq-cart-button--outline:hover' => 'background-color: {{VALUE}};',
],
]
);
$this->add_control(
'text_color',
[
'label' => __('Text Color', 'cannaiq-menus'),
'type' => \Elementor\Controls_Manager::COLOR,
'default' => '#ffffff',
'selectors' => [
'{{WRAPPER}} .cannaiq-cart-button--solid' => 'color: {{VALUE}};',
],
]
);
$this->add_control(
'outline_text_color',
[
'label' => __('Outline Text Color', 'cannaiq-menus'),
'type' => \Elementor\Controls_Manager::COLOR,
'default' => '#1f2937',
'selectors' => [
'{{WRAPPER}} .cannaiq-cart-button--outline' => 'color: {{VALUE}};',
],
'condition' => [
'button_style' => 'outline',
],
]
);
$this->add_control(
'hover_background_color',
[
'label' => __('Hover Background', 'cannaiq-menus'),
'type' => \Elementor\Controls_Manager::COLOR,
'default' => '#374151',
'selectors' => [
'{{WRAPPER}} .cannaiq-cart-button--solid:hover' => 'background-color: {{VALUE}}; border-color: {{VALUE}};',
],
]
);
$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' => 6,
],
'selectors' => [
'{{WRAPPER}} .cannaiq-cart-button' => 'border-radius: {{SIZE}}{{UNIT}};',
],
]
);
$this->add_group_control(
\Elementor\Group_Control_Typography::get_type(),
[
'name' => 'typography',
'selector' => '{{WRAPPER}} .cannaiq-cart-button',
]
);
$this->end_controls_section();
}
protected function render() {
$settings = $this->get_settings_for_display();
// Get URL
$url = '#';
if ($settings['link_source'] === 'custom' && !empty($settings['custom_url']['url'])) {
$url = $settings['custom_url']['url'];
} else {
global $cannaiq_current_product;
if (isset($cannaiq_current_product)) {
$url = $cannaiq_current_product['menuUrl']
?? $cannaiq_current_product['menu_url']
?? $cannaiq_current_product['productUrl']
?? '#';
}
}
// Build classes
$classes = [
'cannaiq-cart-button',
'cannaiq-cart-button--' . $settings['button_style'],
];
if ($settings['full_width'] === 'yes') {
$classes[] = 'cannaiq-cart-button--full';
}
if ($settings['size'] !== 'medium') {
$classes[] = 'cannaiq-cart-button--' . $settings['size'];
}
// Target attribute
$target = $settings['open_in_new_tab'] === 'yes' ? ' target="_blank" rel="noopener noreferrer"' : '';
// Icon SVG (arrow right)
$icon = '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M5 12h14M12 5l7 7-7 7"/></svg>';
?>
<a href="<?php echo esc_url($url); ?>" class="<?php echo esc_attr(implode(' ', $classes)); ?>"<?php echo $target; ?>>
<?php if ($settings['show_icon'] === 'yes' && $settings['icon_position'] === 'before'): ?>
<?php echo $icon; ?>
<?php endif; ?>
<?php echo esc_html($settings['button_text']); ?>
<?php if ($settings['show_icon'] === 'yes' && $settings['icon_position'] === 'after'): ?>
<?php echo $icon; ?>
<?php endif; ?>
</a>
<?php
}
}