start_controls_section( 'section_content', [ 'label' => esc_html__('Content', 'king-addons'), 'tab' => Controls_Manager::TAB_CONTENT, ] ); $this->add_control( 'image', [ 'label' => esc_html__('Image', 'king-addons'), 'type' => Controls_Manager::MEDIA, 'dynamic' => ['active' => true], 'default' => [ 'url' => Utils::get_placeholder_image_src(), ], ] ); $this->add_group_control( Group_Control_Image_Size::get_type(), [ 'name' => 'image_size', 'default' => 'large', ] ); $this->add_control( 'title', [ 'label' => esc_html__('Title', 'king-addons'), 'type' => Controls_Manager::TEXT, 'dynamic' => ['active' => true], 'default' => esc_html__('Archive Banner', 'king-addons'), ] ); $this->add_control( 'description', [ 'label' => esc_html__('Description', 'king-addons'), 'type' => Controls_Manager::TEXTAREA, 'dynamic' => ['active' => true], 'default' => esc_html__('Highlight your category or shop with a banner.', 'king-addons'), ] ); $this->add_control( 'button_text', [ 'label' => esc_html__('Button Text', 'king-addons'), 'type' => Controls_Manager::TEXT, 'dynamic' => ['active' => true], 'default' => '', ] ); $this->add_control( 'button_url', [ 'label' => esc_html__('Button URL', 'king-addons'), 'type' => Controls_Manager::URL, 'dynamic' => ['active' => true], 'placeholder' => 'https://', ] ); $this->add_control( 'use_term_meta', [ 'label' => sprintf(__('Use term meta (Pro) %s', 'king-addons'), ''), 'type' => Controls_Manager::SWITCHER, 'return_value' => 'yes', ] ); $this->add_control( 'title_format', [ 'label' => sprintf(__('Title format %s', 'king-addons'), ''), 'type' => Controls_Manager::TEXT, 'description' => esc_html__('Use {title} and {count}.', 'king-addons'), ] ); $this->add_control( 'desc_format', [ 'label' => sprintf(__('Description format %s', 'king-addons'), ''), 'type' => Controls_Manager::TEXTAREA, 'description' => esc_html__('Use {description}, {title}, {count}.', 'king-addons'), ] ); $this->end_controls_section(); $this->start_controls_section( 'section_style', [ 'label' => esc_html__('Style', 'king-addons'), 'tab' => Controls_Manager::TAB_STYLE, ] ); $this->add_group_control( Group_Control_Typography::get_type(), [ 'name' => 'title_typo', 'selector' => '{{WRAPPER}} .ka-woo-archive-banner__title', ] ); $this->add_control( 'title_color', [ 'label' => esc_html__('Title Color', 'king-addons'), 'type' => Controls_Manager::COLOR, 'selectors' => [ '{{WRAPPER}} .ka-woo-archive-banner__title' => 'color: {{VALUE}};', ], ] ); $this->add_group_control( Group_Control_Typography::get_type(), [ 'name' => 'desc_typo', 'selector' => '{{WRAPPER}} .ka-woo-archive-banner__desc', ] ); $this->add_control( 'desc_color', [ 'label' => esc_html__('Description Color', 'king-addons'), 'type' => Controls_Manager::COLOR, 'selectors' => [ '{{WRAPPER}} .ka-woo-archive-banner__desc' => 'color: {{VALUE}};', ], ] ); $this->add_responsive_control( 'padding', [ 'label' => esc_html__('Padding', 'king-addons'), 'type' => Controls_Manager::DIMENSIONS, 'size_units' => ['px', 'em', '%'], 'selectors' => [ '{{WRAPPER}} .ka-woo-archive-banner__inner' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', ], ] ); $this->end_controls_section(); } protected function render(): void { if (!class_exists('WooCommerce') || !function_exists('is_shop') || !function_exists('is_product_taxonomy')) { return; } if (!$this->should_render()) { $this->render_missing_archive_notice(); return; } $settings = $this->get_settings_for_display(); $can_pro = king_addons_can_use_pro(); $title = $settings['title'] ?? ''; $desc = $settings['description'] ?? ''; $img_html = ''; if (!empty($settings['use_term_meta']) && $can_pro && is_product_taxonomy()) { $term = get_queried_object(); $term_img_id = get_term_meta($term->term_id, 'banner_image', true); $term_title = get_term_meta($term->term_id, 'banner_title', true); $term_desc = get_term_meta($term->term_id, 'banner_desc', true); if ($term_img_id) { // The third argument is the name of a settings key, not an // attachment id - passing the id made Elementor look up // $settings[128], warn, and return nothing. Feed it a synthetic // key so the chosen image size still applies. $img_settings = $settings; $img_settings['ka_term_banner_image'] = [ 'id' => (int) $term_img_id, 'url' => wp_get_attachment_image_url((int) $term_img_id, 'full') ?: '', ]; $img_html = Group_Control_Image_Size::get_attachment_image_html($img_settings, 'image_size', 'ka_term_banner_image'); } if ($term_title) { $title = $term_title; } if ($term_desc) { $desc = $term_desc; } } if ($can_pro) { global $wp_query; $count = isset($wp_query->found_posts) ? (int) $wp_query->found_posts : 0; if (!empty($settings['title_format'])) { $title = str_replace( ['{title}', '{count}'], [$title, number_format_i18n($count)], $settings['title_format'] ); } if (!empty($settings['desc_format'])) { $desc = str_replace( ['{description}', '{title}', '{count}'], [$desc, $title, number_format_i18n($count)], $settings['desc_format'] ); } } if (empty($img_html) && !empty($settings['image']['id'])) { $img_html = Group_Control_Image_Size::get_attachment_image_html($settings, 'image_size', 'image'); } // With no image, title, description or button there is nothing but an // empty shell - which in the editor looks like the widget failed. $has_button = !empty($settings['button_text']) && !empty($settings['button_url']['url']); if (!$img_html && '' === trim((string) $title) && '' === trim((string) $desc) && !$has_button) { if (\Elementor\Plugin::$instance->editor->is_edit_mode()) { echo '