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']; ?>