Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Commit

Permalink
Merge pull request #18 from OM4/feature/fix-storewide-attributes
Browse files Browse the repository at this point in the history
Add support for Global Store-Wide product attributes
  • Loading branch information
thejamescollins authored Jan 17, 2023
2 parents 1328ff6 + c049689 commit be366cb
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
30 changes: 29 additions & 1 deletion includes/Modal/OpenAi_Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,36 @@ protected function build_prompt( WC_Product $product ) {

if ( ! empty( $product->get_attributes() ) ) {
$prompt .= '- Attributes: ';

/**
* Product Attributes can be store-wide or custom per-product attributes.
*
* Logic based on wc_display_product_attributes() function.
*
* @see wc_display_product_attributes()
*/

foreach ( $product->get_attributes() as $attribute ) {
$prompt .= $attribute->get_name() . ': ' . implode( ', ', $attribute->get_options() ) . '. ';
$attribute_name = '';
$attribute_values = array();
if ( $attribute->is_taxonomy() ) {
// Storewide attribute.
$attribute_taxonomy = $attribute->get_taxonomy_object();
$attribute_name = $attribute_taxonomy->attribute_label;
$values = wc_get_product_terms( $product->get_id(), $attribute->get_name(), array( 'fields' => 'all' ) );
foreach ( $values as $attribute_value ) {
$attribute_values[] = esc_html( $attribute_value->name );
}
} else {
// Custom per-product attribute.
$attribute_name = $attribute->get_name();
$attribute_values = $attribute->get_options();
foreach ( $attribute_values as &$value ) {
$value = esc_html( $value );
}
}

$prompt .= esc_html( $attribute_name ) . ': ' . implode( ', ', $attribute_values ) . '. ';
}
$prompt = rtrim( $prompt ) . "\n";
}
Expand Down
6 changes: 6 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ Currently, the plugin is only compatible with WooCommerce. However, we are consi

== Changelog ==

= 0.2 =
* Add support for global store-wide product attributes.

= 0.1.1 =
* Public release for WordPress.org plugin repository.

Expand All @@ -67,6 +70,9 @@ Currently, the plugin is only compatible with WooCommerce. However, we are consi

== Upgrade Notice ==

= 0.2 =
* Add support for global store-wide product attributes.

= 0.1.1 =
* Public release for WordPress.org plugin repository.

Expand Down

0 comments on commit be366cb

Please sign in to comment.