diff --git a/groq-ai-product-text.php b/groq-ai-product-text.php index 6b70708..d922ba0 100644 --- a/groq-ai-product-text.php +++ b/groq-ai-product-text.php @@ -2,7 +2,7 @@ /** * Plugin Name: SitiAI Product Teksten * Description: Genereer productteksten met diverse AI-aanbieders rechtstreeks vanuit WooCommerce. - * Version: 1.4.5 + * Version: 1.5.0 * Author: SitiAI * Text Domain: siti-ai-product-content-generator * Domain Path: /languages diff --git a/includes/Services/Prompt/class-groq-ai-prompt-builder.php b/includes/Services/Prompt/class-groq-ai-prompt-builder.php index 3a49b08..1e18dab 100644 --- a/includes/Services/Prompt/class-groq-ai-prompt-builder.php +++ b/includes/Services/Prompt/class-groq-ai-prompt-builder.php @@ -388,9 +388,66 @@ class Groq_AI_Prompt_Builder { } } + if ( ! empty( $fields['brands'] ) ) { + $brands_context = $this->get_product_brand_context_text( $post_id ); + if ( '' !== $brands_context ) { + $parts[] = sprintf( __( 'Merken: %s', GROQ_AI_PRODUCT_TEXT_DOMAIN ), $brands_context ); + } + } + return implode( "\n\n", array_filter( $parts ) ); } + private function get_product_brand_context_text( $post_id ) { + $post_id = absint( $post_id ); + $taxonomy = $this->detect_brand_taxonomy(); + + if ( ! $post_id || '' === $taxonomy || ! taxonomy_exists( $taxonomy ) ) { + return ''; + } + + $terms = get_the_terms( $post_id, $taxonomy ); + if ( empty( $terms ) || is_wp_error( $terms ) ) { + return ''; + } + + $entries = []; + foreach ( $terms as $term ) { + if ( ! $term || ! is_object( $term ) ) { + continue; + } + + $name = isset( $term->name ) ? trim( wp_strip_all_tags( (string) $term->name ) ) : ''; + if ( '' === $name ) { + continue; + } + + $description = isset( $term->description ) ? trim( wp_strip_all_tags( (string) $term->description ) ) : ''; + if ( '' !== $description ) { + $entries[] = sprintf( '%s - %s', $name, $description ); + } else { + $entries[] = $name; + } + } + + $entries = array_values( array_unique( array_filter( $entries ) ) ); + if ( empty( $entries ) ) { + return ''; + } + + $context = implode( '; ', $entries ); + + /** + * Filters the product brand context string added to prompts. + * + * @param string $context + * @param int $post_id + * @param array $terms + * @param string $taxonomy + */ + return (string) apply_filters( 'groq_ai_product_brand_context', $context, $post_id, $terms, $taxonomy ); + } + public function prepend_context_to_prompt( $prompt, $context ) { $context = trim( (string) $context ); diff --git a/includes/Services/Settings/class-groq-ai-settings-manager.php b/includes/Services/Settings/class-groq-ai-settings-manager.php index 9f4c996..a82724c 100644 --- a/includes/Services/Settings/class-groq-ai-settings-manager.php +++ b/includes/Services/Settings/class-groq-ai-settings-manager.php @@ -234,6 +234,11 @@ class Groq_AI_Settings_Manager { 'description' => __( 'Voeg gestructureerde productattributen toe (zoals kleur, maat, materiaal).', GROQ_AI_PRODUCT_TEXT_DOMAIN ), 'default' => false, ], + 'brands' => [ + 'label' => __( 'Merken', GROQ_AI_PRODUCT_TEXT_DOMAIN ), + 'description' => __( 'Voegt gekoppelde productmerken toe (detecteert WooCommerce merk-taxonomieën).', GROQ_AI_PRODUCT_TEXT_DOMAIN ), + 'default' => true, + ], 'images' => [ 'label' => __( 'Afbeeldingen', GROQ_AI_PRODUCT_TEXT_DOMAIN ), 'description' => __( 'Voeg een korte lijst toe met productafbeeldingen (beschrijving + URL).', GROQ_AI_PRODUCT_TEXT_DOMAIN ), @@ -261,7 +266,7 @@ class Groq_AI_Settings_Manager { $normalized = []; foreach ( $definitions as $key => $data ) { - $normalized[ $key ] = false; + $normalized[ $key ] = ! empty( $data['default'] ); } if ( ! is_array( $fields ) ) {