start_controls_section( 'section_style', array( 'label' => __( 'Style', 'ai-discoverability-kit' ), ) ); $this->add_control( 'style', array( 'label' => __( 'Display Style', 'ai-discoverability-kit' ), 'type' => Controls_Manager::SELECT, 'default' => 'badge', 'options' => array( 'badge' => __( 'Badge (Circle)', 'ai-discoverability-kit' ), 'bar' => __( 'Progress Bar', 'ai-discoverability-kit' ), 'minimal' => __( 'Minimal (Number)', 'ai-discoverability-kit' ), ), ) ); $this->add_control( 'show_label', array( 'label' => __( 'Show Label', 'ai-discoverability-kit' ), 'type' => Controls_Manager::SWITCHER, 'label_on' => __( 'Yes', 'ai-discoverability-kit' ), 'label_off' => __( 'No', 'ai-discoverability-kit' ), 'return_value' => 'yes', 'default' => 'yes', ) ); $this->add_control( 'primary_color', array( 'label' => __( 'Primary Color', 'ai-discoverability-kit' ), 'type' => Controls_Manager::COLOR, 'default' => '#00e58a', ) ); $this->add_control( 'font_size', array( 'label' => __( 'Font Size', 'ai-discoverability-kit' ), 'type' => Controls_Manager::SLIDER, 'size_units' => array( 'px' ), 'range' => array( 'px' => array( 'min' => 12, 'max' => 72, ), ), 'default' => array( 'unit' => 'px', 'size' => 24, ), ) ); $this->end_controls_section(); } /** * Render widget output. * * @return void */ protected function render(): void { $product_id = get_the_ID(); if ( ! function_exists( 'wc_get_product' ) ) { return; } $product = wc_get_product( $product_id ); if ( ! $product || ! $product->is_type( array( 'simple', 'variable', 'grouped', 'external' ) ) ) { return; } $readiness = new \AICommerce\Analytics\ReadinessScore( new \AICommerce\Schema\ProductSchema(), new \AICommerce\Schema\Validator() ); $result = $readiness->calculate_and_cache( $product ); $score = (int) ( $result['overall'] ?? 0 ); $style = $this->get_settings_for_display( 'style' ); $show_label = 'yes' === $this->get_settings_for_display( 'show_label' ); $color = $this->get_settings_for_display( 'primary_color' ); $font_data = $this->get_settings_for_display( 'font_size' ); $font_size = ( $font_data['size'] ?? 24 ) . 'px'; if ( function_exists( 'aicommerce_render_score_badge' ) ) { // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Helper already escapes. echo aicommerce_render_score_badge( $score, $style, $show_label, $color, $font_size ); } } }