product_name */ protected function get_products_for_select() { $options = ['' => __('-- Select a Product --', 'crawlsy-menus')]; $plugin = Crawlsy_Menus_Plugin::instance(); $products = $plugin->fetch_products(['limit' => 500]); if ($products && is_array($products)) { foreach ($products as $product) { $label = $product['name']; if (!empty($product['brand'])) { $label = $product['brand'] . ' - ' . $label; } if (!empty($product['category'])) { $label .= ' (' . $product['category'] . ')'; } $options[$product['id']] = $label; } } return $options; } protected function register_controls() { // Content Section $this->start_controls_section( 'content_section', [ 'label' => __('Content', 'crawlsy-menus'), 'tab' => \Elementor\Controls_Manager::TAB_CONTENT, ] ); // Get products for the select dropdown $products_options = $this->get_products_for_select(); $this->add_control( 'product_id', [ 'label' => __('Select Product', 'crawlsy-menus'), 'type' => \Elementor\Controls_Manager::SELECT2, 'options' => $products_options, 'default' => '', 'label_block' => true, 'description' => __('Search and select a product to display', 'crawlsy-menus'), ] ); $this->add_control( 'product_id_manual', [ 'label' => __('Or Enter Product ID', 'crawlsy-menus'), 'type' => \Elementor\Controls_Manager::NUMBER, 'default' => '', 'description' => __('Manually enter a product ID if not found in dropdown', 'crawlsy-menus'), 'condition' => [ 'product_id' => '', ], ] ); $this->add_control( 'layout', [ 'label' => __('Layout', 'crawlsy-menus'), 'type' => \Elementor\Controls_Manager::SELECT, 'default' => 'horizontal', 'options' => [ 'horizontal' => __('Horizontal', 'crawlsy-menus'), 'vertical' => __('Vertical', 'crawlsy-menus'), ], ] ); $this->end_controls_section(); // Display Options Section $this->start_controls_section( 'display_section', [ 'label' => __('Display Options', 'crawlsy-menus'), 'tab' => \Elementor\Controls_Manager::TAB_CONTENT, ] ); $this->add_control( 'show_image', [ 'label' => __('Show Image', 'crawlsy-menus'), 'type' => \Elementor\Controls_Manager::SWITCHER, 'label_on' => __('Yes', 'crawlsy-menus'), 'label_off' => __('No', 'crawlsy-menus'), 'return_value' => 'yes', 'default' => 'yes', ] ); $this->add_control( 'show_price', [ 'label' => __('Show Price', 'crawlsy-menus'), 'type' => \Elementor\Controls_Manager::SWITCHER, 'label_on' => __('Yes', 'crawlsy-menus'), 'label_off' => __('No', 'crawlsy-menus'), 'return_value' => 'yes', 'default' => 'yes', ] ); $this->add_control( 'show_description', [ 'label' => __('Show Description', 'crawlsy-menus'), 'type' => \Elementor\Controls_Manager::SWITCHER, 'label_on' => __('Yes', 'crawlsy-menus'), 'label_off' => __('No', 'crawlsy-menus'), 'return_value' => 'yes', 'default' => 'yes', ] ); $this->add_control( 'show_thc', [ 'label' => __('Show THC', 'crawlsy-menus'), 'type' => \Elementor\Controls_Manager::SWITCHER, 'label_on' => __('Yes', 'crawlsy-menus'), 'label_off' => __('No', 'crawlsy-menus'), 'return_value' => 'yes', 'default' => 'yes', ] ); $this->add_control( 'show_cbd', [ 'label' => __('Show CBD', 'crawlsy-menus'), 'type' => \Elementor\Controls_Manager::SWITCHER, 'label_on' => __('Yes', 'crawlsy-menus'), 'label_off' => __('No', 'crawlsy-menus'), 'return_value' => 'yes', 'default' => 'yes', ] ); $this->add_control( 'show_terpenes', [ 'label' => __('Show Terpenes', 'crawlsy-menus'), 'type' => \Elementor\Controls_Manager::SWITCHER, 'label_on' => __('Yes', 'crawlsy-menus'), 'label_off' => __('No', 'crawlsy-menus'), 'return_value' => 'yes', 'default' => 'yes', ] ); $this->add_control( 'show_effects', [ 'label' => __('Show Effects', 'crawlsy-menus'), 'type' => \Elementor\Controls_Manager::SWITCHER, 'label_on' => __('Yes', 'crawlsy-menus'), 'label_off' => __('No', 'crawlsy-menus'), 'return_value' => 'yes', 'default' => 'yes', ] ); $this->add_control( 'show_brand', [ 'label' => __('Show Brand', 'crawlsy-menus'), 'type' => \Elementor\Controls_Manager::SWITCHER, 'label_on' => __('Yes', 'crawlsy-menus'), 'label_off' => __('No', 'crawlsy-menus'), 'return_value' => 'yes', 'default' => 'yes', ] ); $this->end_controls_section(); // Style Section $this->start_controls_section( 'style_section', [ 'label' => __('Style', 'crawlsy-menus'), 'tab' => \Elementor\Controls_Manager::TAB_STYLE, ] ); $this->add_control( 'background_color', [ 'label' => __('Background Color', 'crawlsy-menus'), 'type' => \Elementor\Controls_Manager::COLOR, 'default' => '#ffffff', 'selectors' => [ '{{WRAPPER}} .crawlsy-single-product' => 'background-color: {{VALUE}};', ], ] ); $this->add_control( 'border_radius', [ 'label' => __('Border Radius', 'crawlsy-menus'), 'type' => \Elementor\Controls_Manager::SLIDER, 'size_units' => ['px'], 'range' => [ 'px' => [ 'min' => 0, 'max' => 50, ], ], 'default' => [ 'size' => 8, ], 'selectors' => [ '{{WRAPPER}} .crawlsy-single-product' => 'border-radius: {{SIZE}}{{UNIT}};', ], ] ); $this->add_control( 'text_color', [ 'label' => __('Text Color', 'crawlsy-menus'), 'type' => \Elementor\Controls_Manager::COLOR, 'default' => '#333333', 'selectors' => [ '{{WRAPPER}} .crawlsy-single-product' => 'color: {{VALUE}};', ], ] ); $this->end_controls_section(); } protected function render() { $settings = $this->get_settings_for_display(); // Use dropdown selection, or fall back to manual ID $product_id = !empty($settings['product_id']) ? $settings['product_id'] : $settings['product_id_manual']; if (empty($product_id)) { echo '

' . __('Please select or enter a product ID.', 'crawlsy-menus') . '

'; return; } $plugin = Crawlsy_Menus_Plugin::instance(); $product = $plugin->fetch_product($product_id); if (!$product) { echo '

' . __('Product not found.', 'crawlsy-menus') . '

'; return; } $layout = $settings['layout']; ?>
<?php echo esc_attr($product['name']); ?>

$