WooCommerce Code Reference

Metadata
in package

Attaches a name/value metadata entry to a code-API element.

(class, class property, method parameter, method parameter, or enum case).

Metadata entries are harvested by ApiBuilder and emitted into the generated schema, where they can be queried at runtime through the top-level _apiMetadata GraphQL field. The mechanism is intentionally open: subclass this attribute to ship a category of metadata (e.g. {@see} for marking elements as for WooCommerce internal use). Tooling discovers metadata by name; the value is scalar-only so it can flow through GraphQL without additional encoding.

Two metadata entries with the same name on the same element produce a build-time error, see ApiBuilder for the duplicate-name detection. Multiple distinct names on one element are allowed.

Table of Contents

__construct()  : mixed
Constructor.
get_name()  : string
The entry's name (e.g. `internal`, `beta`, `owner`).
get_value()  : bool|int|float|string|null
The entry's scalar value.
shows_in_metadata_query()  : bool
Whether the element carrying this attribute should appear in the `_apiMetadata` discovery query.

Methods

__construct()

Constructor.

public __construct(string $name, bool|int|float|string|null $value) : mixed
Parameters
$name : string

Identifier for this entry. Must be unique per element across all Metadata subclasses applied to it.

$value : bool|int|float|string|null

Scalar payload exposed to clients via _apiMetadata.

Return values
mixed

get_value()

The entry's scalar value.

public get_value() : bool|int|float|string|null
Return values
bool|int|float|string|null

shows_in_metadata_query()

Whether the element carrying this attribute should appear in the `_apiMetadata` discovery query.

public shows_in_metadata_query() : bool

Returning false removes the element's row entirely from _apiMetadata — neither this metadata entry nor any other descriptor on the same target surfaces. The runtime gates and any description transforms are unaffected. Useful for plugins that attach internal routing or feature hints they prefer not to broadcast through the discovery channel.

Despite the colloquial naming around it, this has nothing to do with native GraphQL introspection (__schema / __type); those queries continue to expose the schema's shape as usual.

Because this is an instance method, subclasses can decide conditionally based on their own constructor arguments.

Return values
bool