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>
310 lines
10 KiB
PHP
310 lines
10 KiB
PHP
<?php
|
|
/**
|
|
* CannaIQ Price Block Widget
|
|
*
|
|
* Displays product price with optional sale price and weight.
|
|
*
|
|
* @package CannaIQ_Menus
|
|
* @since 2.0.0
|
|
*/
|
|
|
|
if (!defined('ABSPATH')) {
|
|
exit;
|
|
}
|
|
|
|
class CannaIQ_Price_Block_Widget extends \Elementor\Widget_Base {
|
|
|
|
public function get_name() {
|
|
return 'cannaiq_price_block';
|
|
}
|
|
|
|
public function get_title() {
|
|
return __('Price Block', 'cannaiq-menus');
|
|
}
|
|
|
|
public function get_icon() {
|
|
return 'eicon-product-price';
|
|
}
|
|
|
|
public function get_categories() {
|
|
return ['cannaiq'];
|
|
}
|
|
|
|
public function get_keywords() {
|
|
return ['price', 'sale', 'cost', 'money', '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' => __('Price 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_price',
|
|
[
|
|
'label' => __('Regular Price', 'cannaiq-menus'),
|
|
'type' => \Elementor\Controls_Manager::NUMBER,
|
|
'default' => 45,
|
|
'min' => 0,
|
|
'step' => 0.01,
|
|
'condition' => [
|
|
'source' => 'custom',
|
|
],
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'custom_sale_price',
|
|
[
|
|
'label' => __('Sale Price (optional)', 'cannaiq-menus'),
|
|
'type' => \Elementor\Controls_Manager::NUMBER,
|
|
'default' => '',
|
|
'min' => 0,
|
|
'step' => 0.01,
|
|
'condition' => [
|
|
'source' => 'custom',
|
|
],
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'show_original_when_sale',
|
|
[
|
|
'label' => __('Show Original Price on Sale', '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_weight',
|
|
[
|
|
'label' => __('Show Weight', '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(
|
|
'custom_weight',
|
|
[
|
|
'label' => __('Weight Text', 'cannaiq-menus'),
|
|
'type' => \Elementor\Controls_Manager::TEXT,
|
|
'default' => '1/8 oz',
|
|
'condition' => [
|
|
'source' => 'custom',
|
|
'show_weight' => 'yes',
|
|
],
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'layout',
|
|
[
|
|
'label' => __('Layout', 'cannaiq-menus'),
|
|
'type' => \Elementor\Controls_Manager::SELECT,
|
|
'default' => 'inline',
|
|
'options' => [
|
|
'inline' => __('Inline', 'cannaiq-menus'),
|
|
'stacked' => __('Stacked', 'cannaiq-menus'),
|
|
],
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'currency_symbol',
|
|
[
|
|
'label' => __('Currency Symbol', 'cannaiq-menus'),
|
|
'type' => \Elementor\Controls_Manager::TEXT,
|
|
'default' => '$',
|
|
]
|
|
);
|
|
|
|
$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(
|
|
'price_color',
|
|
[
|
|
'label' => __('Price Color', 'cannaiq-menus'),
|
|
'type' => \Elementor\Controls_Manager::COLOR,
|
|
'default' => '#1f2937',
|
|
'selectors' => [
|
|
'{{WRAPPER}} .cannaiq-price-block__regular' => 'color: {{VALUE}};',
|
|
],
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'sale_color',
|
|
[
|
|
'label' => __('Sale Price Color', 'cannaiq-menus'),
|
|
'type' => \Elementor\Controls_Manager::COLOR,
|
|
'default' => '#dc2626',
|
|
'selectors' => [
|
|
'{{WRAPPER}} .cannaiq-price-block__sale' => 'color: {{VALUE}};',
|
|
],
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'original_color',
|
|
[
|
|
'label' => __('Original Price Color', 'cannaiq-menus'),
|
|
'type' => \Elementor\Controls_Manager::COLOR,
|
|
'default' => '#9ca3af',
|
|
'selectors' => [
|
|
'{{WRAPPER}} .cannaiq-price-block__original' => 'color: {{VALUE}};',
|
|
],
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'weight_color',
|
|
[
|
|
'label' => __('Weight Color', 'cannaiq-menus'),
|
|
'type' => \Elementor\Controls_Manager::COLOR,
|
|
'default' => '#9ca3af',
|
|
'selectors' => [
|
|
'{{WRAPPER}} .cannaiq-price-block__weight' => 'color: {{VALUE}};',
|
|
],
|
|
]
|
|
);
|
|
|
|
$this->add_group_control(
|
|
\Elementor\Group_Control_Typography::get_type(),
|
|
[
|
|
'name' => 'price_typography',
|
|
'label' => __('Price Typography', 'cannaiq-menus'),
|
|
'selector' => '{{WRAPPER}} .cannaiq-price-block__sale, {{WRAPPER}} .cannaiq-price-block__regular',
|
|
]
|
|
);
|
|
|
|
$this->end_controls_section();
|
|
}
|
|
|
|
protected function render() {
|
|
$settings = $this->get_settings_for_display();
|
|
|
|
// Get price values
|
|
$regular_price = 0;
|
|
$sale_price = null;
|
|
$weight = '';
|
|
|
|
if ($settings['source'] === 'custom') {
|
|
$regular_price = floatval($settings['custom_price']);
|
|
$sale_price = !empty($settings['custom_sale_price']) ? floatval($settings['custom_sale_price']) : null;
|
|
$weight = $settings['custom_weight'];
|
|
} else {
|
|
global $cannaiq_current_product;
|
|
if (isset($cannaiq_current_product)) {
|
|
$regular_price = $cannaiq_current_product['Prices'][0]
|
|
?? $cannaiq_current_product['recPrices'][0]
|
|
?? $cannaiq_current_product['regular_price']
|
|
?? 0;
|
|
|
|
$sale_price = $cannaiq_current_product['specialPrice']
|
|
?? $cannaiq_current_product['sale_price']
|
|
?? null;
|
|
|
|
// Check POSMetaData for prices
|
|
if (isset($cannaiq_current_product['POSMetaData']['children'][0])) {
|
|
$child = $cannaiq_current_product['POSMetaData']['children'][0];
|
|
if (isset($child['price'])) {
|
|
$regular_price = $child['price'];
|
|
}
|
|
if (isset($child['specialPrice']) && $child['specialPrice'] > 0) {
|
|
$sale_price = $child['specialPrice'];
|
|
}
|
|
}
|
|
|
|
$weight = $cannaiq_current_product['Options'][0]
|
|
?? $cannaiq_current_product['rawOptions'][0]
|
|
?? $cannaiq_current_product['weight']
|
|
?? '';
|
|
}
|
|
}
|
|
|
|
$regular_price = floatval($regular_price);
|
|
if ($regular_price <= 0) {
|
|
return;
|
|
}
|
|
|
|
// Determine if on sale
|
|
$is_on_sale = $sale_price !== null && floatval($sale_price) > 0 && floatval($sale_price) < $regular_price;
|
|
|
|
// Build classes
|
|
$classes = ['cannaiq-price-block'];
|
|
if ($settings['layout'] === 'stacked') {
|
|
$classes[] = 'cannaiq-price-block--stacked';
|
|
}
|
|
if ($settings['size'] !== 'medium') {
|
|
$classes[] = 'cannaiq-price-block--' . $settings['size'];
|
|
}
|
|
|
|
$currency = $settings['currency_symbol'];
|
|
?>
|
|
<div class="<?php echo esc_attr(implode(' ', $classes)); ?>">
|
|
<?php if ($settings['show_weight'] === 'yes' && !empty($weight)): ?>
|
|
<span class="cannaiq-price-block__weight"><?php echo esc_html($weight); ?></span>
|
|
<?php endif; ?>
|
|
|
|
<?php if ($is_on_sale): ?>
|
|
<?php if ($settings['show_original_when_sale'] === 'yes'): ?>
|
|
<span class="cannaiq-price-block__original"><?php echo esc_html($currency . number_format($regular_price, 2)); ?></span>
|
|
<?php endif; ?>
|
|
<span class="cannaiq-price-block__sale"><?php echo esc_html($currency . number_format(floatval($sale_price), 2)); ?></span>
|
|
<?php else: ?>
|
|
<span class="cannaiq-price-block__regular"><?php echo esc_html($currency . number_format($regular_price, 2)); ?></span>
|
|
<?php endif; ?>
|
|
</div>
|
|
<?php
|
|
}
|
|
}
|