diff --git a/assets/js/admin.js b/assets/js/admin.js
index 10b6313..4ca64a8 100644
--- a/assets/js/admin.js
+++ b/assets/js/admin.js
@@ -13,6 +13,7 @@
const resultField = document.getElementById('groq-ai-output');
const jsonCopyButton = modal.querySelector('.groq-ai-copy-json');
const contextToggles = modal.querySelectorAll('.groq-ai-context-toggle');
+ const attributeToggles = modal.querySelectorAll('.groq-ai-attribute-toggle');
const resultFields = {};
modal.querySelectorAll('.groq-ai-result-field').forEach((field) => {
const key = field.getAttribute('data-field');
@@ -60,6 +61,7 @@
promptField.value = GroqAIGenerator.defaultPrompt;
}
resetContextToggles();
+ resetAttributeToggles();
setTimeout(() => promptField.focus(), 50);
}
@@ -115,6 +117,7 @@
payload.append('prompt', prompt);
payload.append('post_id', GroqAIGenerator.postId || 0);
payload.append('context_fields', JSON.stringify(collectContextSelection()));
+ payload.append('attribute_includes', JSON.stringify(collectAttributeSelection()));
toggleLoading(true);
resultWrapper.hidden = true;
@@ -458,6 +461,20 @@
});
}
+ function resetAttributeToggles() {
+ const defaults = Array.isArray(GroqAIGenerator.attributeIncludesDefaults)
+ ? GroqAIGenerator.attributeIncludesDefaults
+ : [];
+
+ attributeToggles.forEach((toggle) => {
+ const key = toggle.getAttribute('data-attribute');
+ if (!key) {
+ return;
+ }
+ toggle.checked = defaults.includes(key);
+ });
+ }
+
function collectContextSelection() {
const selected = [];
contextToggles.forEach((toggle) => {
@@ -467,4 +484,18 @@
});
return selected;
}
+
+ function collectAttributeSelection() {
+ const selected = [];
+ attributeToggles.forEach((toggle) => {
+ if (!toggle.checked) {
+ return;
+ }
+ const key = toggle.getAttribute('data-attribute');
+ if (key) {
+ selected.push(key);
+ }
+ });
+ return selected;
+ }
})(jQuery);
diff --git a/groq-ai-product-text.php b/groq-ai-product-text.php
index 753d3b3..6b70708 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.4
+ * Version: 1.4.5
* Author: SitiAI
* Text Domain: siti-ai-product-content-generator
* Domain Path: /languages
diff --git a/includes/Admin/class-groq-ai-product-ui.php b/includes/Admin/class-groq-ai-product-ui.php
index 0b3ffd2..fccf191 100644
--- a/includes/Admin/class-groq-ai-product-ui.php
+++ b/includes/Admin/class-groq-ai-product-ui.php
@@ -59,6 +59,9 @@ class Groq_AI_Product_Text_Product_UI {
$post_id = ( $post && isset( $post->ID ) ) ? (int) $post->ID : 0;
$settings = $this->plugin->get_settings();
+ $attribute_defaults = isset( $settings['product_attribute_includes'] ) && is_array( $settings['product_attribute_includes'] )
+ ? array_values( array_unique( array_map( 'sanitize_key', $settings['product_attribute_includes'] ) ) )
+ : [];
wp_localize_script(
'groq-ai-admin',
@@ -69,6 +72,7 @@ class Groq_AI_Product_Text_Product_UI {
'defaultPrompt' => $settings['default_prompt'],
'postId' => $post_id,
'contextDefaults' => isset( $settings['context_fields'] ) ? $settings['context_fields'] : $this->plugin->get_default_context_fields(),
+ 'attributeIncludesDefaults' => $attribute_defaults,
]
);
}
@@ -82,6 +86,7 @@ class Groq_AI_Product_Text_Product_UI {
$settings = $this->plugin->get_settings();
$rankmath_enabled = $this->plugin->is_rankmath_active() && $this->plugin->is_module_enabled( 'rankmath', $settings );
+ $attribute_options = $this->get_product_attribute_include_options();
?>
@@ -109,6 +114,9 @@ class Groq_AI_Product_Text_Product_UI {
$context_definitions = $this->plugin->get_context_field_definitions();
$context_defaults = isset( $settings['context_fields'] ) ? $settings['context_fields'] : $this->plugin->get_default_context_fields();
foreach ( $context_definitions as $context_key => $context_info ) :
+ if ( 'attributes' === $context_key ) {
+ continue;
+ }
$checked = ! empty( $context_defaults[ $context_key ] );
?>
+
+
+
+
+
+
+
+ $attr_label ) : ?>
+
+
+
+
@@ -225,4 +250,39 @@ class Groq_AI_Product_Text_Product_UI {
__( 'Custom attributen (niet-taxonomie)', GROQ_AI_PRODUCT_TEXT_DOMAIN ),
+ ];
+
+ if ( function_exists( 'wc_get_attribute_taxonomies' ) ) {
+ $taxonomies = wc_get_attribute_taxonomies();
+ if ( is_array( $taxonomies ) ) {
+ foreach ( $taxonomies as $attr ) {
+ $name = isset( $attr->attribute_name ) ? sanitize_key( (string) $attr->attribute_name ) : '';
+ $label = isset( $attr->attribute_label ) ? sanitize_text_field( (string) $attr->attribute_label ) : '';
+ if ( '' === $name ) {
+ continue;
+ }
+ $taxonomy = 'pa_' . $name;
+ if ( '' === $label ) {
+ $label = function_exists( 'wc_attribute_label' ) ? wc_attribute_label( $taxonomy ) : $taxonomy;
+ }
+ $options[ $taxonomy ] = $label;
+ }
+ }
+ }
+
+ if ( count( $options ) > 1 ) {
+ $fixed = [
+ '__custom__' => $options['__custom__'],
+ ];
+ unset( $options['__custom__'] );
+ asort( $options, SORT_NATURAL | SORT_FLAG_CASE );
+ $options = $fixed + $options;
+ }
+
+ return $options;
+ }
}
diff --git a/includes/Admin/class-groq-ai-settings-page.php b/includes/Admin/class-groq-ai-settings-page.php
index b9bc0d7..164e4d8 100644
--- a/includes/Admin/class-groq-ai-settings-page.php
+++ b/includes/Admin/class-groq-ai-settings-page.php
@@ -689,6 +689,14 @@ class Groq_AI_Product_Text_Settings_Page {
'groq_ai_product_text_prompts'
);
+ add_settings_field(
+ 'groq_ai_product_attribute_includes',
+ __( 'Productattributen meesturen', GROQ_AI_PRODUCT_TEXT_DOMAIN ),
+ [ $this, 'render_product_attribute_includes_field' ],
+ 'groq-ai-product-text-prompts',
+ 'groq_ai_product_text_prompts'
+ );
+
add_settings_field(
'groq_ai_response_format_compat',
__( 'Response-format compatibiliteit', GROQ_AI_PRODUCT_TEXT_DOMAIN ),
@@ -1636,6 +1644,9 @@ class Groq_AI_Product_Text_Settings_Page {
?>
$definition ) :
+ if ( 'attributes' === $key ) {
+ continue;
+ }
$checked = ! empty( $values[ $key ] );
?>