Dynamic data to display the image of a WooCommerce brand category

Hello,
I would like to create dynamic data to display the image of a WooCommerce brand category.
Not knowing how to code, I use chatgpt, it usually works.

chatgpt code:
/**

  • Tag dynamique Bricks : {brand_archive_image}
    • Sur une archive de marque → image de la marque courante
    • Sur une fiche produit → image de la premiĂšre marque du produit
      */

if ( ! function_exists( ‘my_bricks_add_brand_image_dynamic_tag’ ) ) {

// 1. Déclarer le tag dans Bricks
add_filter( 'bricks/dynamic_tags_list', 'my_bricks_add_brand_image_dynamic_tag' );
function my_bricks_add_brand_image_dynamic_tag( $tags ) {

	$tags[] = [
		// Nom du tag tel qu’il apparaütra dans Bricks
		'name'  => '{brand_archive_image}',
		'label' => 'Image marque (archive)',
		'group' => 'WooCommerce',
	];

	return $tags;
}

// 2. Renvoyer la valeur du tag
add_filter( 'bricks/dynamic_data/render_tag', 'my_bricks_render_brand_image_dynamic_tag', 20, 3 );
function my_bricks_render_brand_image_dynamic_tag( $tag, $post, $context = 'text' ) {

	if ( ! is_string( $tag ) ) {
		return $tag;
	}

	// On enlĂšve les { } pour comparer
	$clean_tag = str_replace( [ '{', '}' ], '', $tag );

	// On ne traite que notre tag
	if ( $clean_tag !== 'brand_archive_image' ) {
		return $tag;
	}

	// ---- Récupération du terme de marque ----

	$brand_term = null;

	// 1) On est sur une archive de marque ?
	if ( is_tax( 'product_brand' ) ) { // <-- change 'product_brand' si ta taxonomie est différente
		$brand_term = get_queried_object();
	}

	// 2) Sinon, on est peut-ĂȘtre sur une fiche produit : on prend la 1Ăšre marque
	if ( ! $brand_term && $post instanceof WP_Post ) {
		$terms = get_the_terms( $post->ID, 'product_brand' ); // <-- idem ici si taxo différente

		if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
			$brand_term = $terms[0];
		}
	}

	if ( ! $brand_term || empty( $brand_term->term_id ) ) {
		return '';
	}

	// ---- Récupération de l'image de la marque ----

	// Meta standard du plugin WooCommerce Brands : 'thumbnail_id'
	$thumbnail_id = get_term_meta( $brand_term->term_id, 'thumbnail_id', true ); // <-- adapte le meta key si besoin

	if ( ! $thumbnail_id ) {
		return '';
	}

	// On rĂ©cupĂšre l’URL de l’image en taille "full"
	$image_url = wp_get_attachment_image_url( $thumbnail_id, 'full' );

	if ( ! $image_url ) {
		return '';
	}

	// Pour un contrîle image Bricks, l’URL suffit
	return $image_url;
}

}




I asked chatgpt another way.
He provided me with this code which works, but I have to use {echo:brx_get_brand_archive_image_id}

> <?php
> /**
>  * Retourne l'ID de l'image d'archive de la marque WooCommerce.
>  *
>  * - Sur une archive de marque (taxonomy product_brand) : prend la marque courante.
>  * - Sur un produit : prend la premiÚre marque associée au produit.
>  *
>  * Taxonomy utilisée : product_brand (WooCommerce Brands / WooCommerce 9.6+).
>  * Si ta taxonomy a un autre slug, change 'product_brand' ci-dessous.
>  */
> if ( ! function_exists( 'brx_get_brand_archive_image_id' ) ) {
> 	function brx_get_brand_archive_image_id() {
> 		$taxonomy = 'product_brand'; // À adapter si besoin (ex: 'pa_brand')
> 		$term = null;
> 		// 1) Cas : page d'archive de marque
> 		if ( is_tax( $taxonomy ) ) {
> 			$term = get_queried_object();
> 		}
> 		// 2) Cas : page produit ou boucle produit
> 		if ( ! $term ) {
> 			$post_id = get_the_ID();
> 			if ( ! $post_id ) {
> 				return '';
> 			}
> 			$terms = get_the_terms( $post_id, $taxonomy );
> 			if ( empty( $terms ) || is_wp_error( $terms ) ) {
> 				return '';
> 			}
> 			// On prend la premiÚre marque trouvée
> 			$term = array_shift( $terms );
> 		}
> 		if ( ! $term || empty( $term->term_id ) ) {
> 			return '';
> 		}
> 		// WooCommerce Brands stocke le logo dans la meta 'thumbnail_id'
> 		$thumb_id = get_term_meta( $term->term_id, 'thumbnail_id', true );
> 		if ( ! $thumb_id ) {
> 			return '';
> 		}
> 		// IMPORTANT : on retourne l'ID de l'image (Bricks sait le gérer en contexte "image")
> 		return (int) $thumb_id;
> 	}
> }
> /**
>  * Autoriser la fonction pour le tag {echo:...} de Bricks (Bricks 1.9.7+)
>  */
> add_filter( 'bricks/code/echo_function_names', function( $functions ) {
> 	if ( ! is_array( $functions ) ) {
> 		$functions = [];
> 	}
> 	$functions[] = 'brx_get_brand_archive_image_id';
> 	return $functions;
> } );

It would be interesting to be able to display images from the “brand” archive natively in Bricks using dynamic data.