$fields Field values. * @param WP_Post $post The post. * @param Node_Context $c Page information. * @param Graph $graph The graph. * @return array|null */ public function build( string $type, array $fields, WP_Post $post, Node_Context $c, Graph $graph ): ?array { $name = $this->text( $fields, 'name', $this->title( $post ) ); $offer = $this->offer( $fields, '', $c->url ); $rating = $this->aggregate_rating( $fields ); if ( '' === $name || ( null === $offer && null === $rating ) ) { return null; } $brand = $this->text( $fields, 'brand' ); return array( '@type' => 'Product', '@id' => $c->id( 'product' ), 'mainEntityOfPage' => array( '@id' => $c->id( 'webpage' ) ), 'url' => $c->url, 'name' => $name, 'description' => $this->text( $fields, 'description', $this->description( $post, $c ) ), 'image' => $this->image_url( $fields, 'image', $post ), 'brand' => '' !== $brand ? array( '@type' => 'Brand', 'name' => $brand, ) : null, 'sku' => $this->text( $fields, 'sku' ), 'gtin' => $this->text( $fields, 'gtin' ), 'mpn' => $this->text( $fields, 'mpn' ), 'offers' => $offer, 'aggregateRating' => $rating, ); } }