WooCommerce Code Reference

ExtendSchema
in package

Provides utility functions to extend Store API schemas.

Note there are also helpers that map to these methods.

Tags
see
woocommerce_store_api_register_endpoint_data()
see
woocommerce_store_api_register_update_callback()
see
woocommerce_store_api_register_payment_requirements()
see
woocommerce_store_api_get_formatter()

Table of Contents

$callback_methods  : array<string|int, mixed>
Data to be extended
$endpoints  : array<string|int, string>
List of Store API schema that is allowed to be extended by extensions.
$extend_data  : array<string|int, mixed>
Data to be extended
$formatters  : Formatters
Holds the formatters class instance.
$payment_requirements  : array<string|int, mixed>
Array of payment requirements
__construct()  : mixed
Constructor
get_endpoint_data()  : object
Returns the registered endpoint data
get_endpoint_schema()  : object
Returns the registered endpoint schema
get_formatter()  : FormatterInterface
Returns a formatter instance.
get_payment_requirements()  : array<string|int, mixed>
Returns the additional payment requirements for the cart which are required to make payments. Values listed here are compared against each Payment Gateways "supports" flag.
get_update_callback()  : callable
Get callback for a specific endpoint and namespace.
register_endpoint_data()  : mixed
Register endpoint data under a specified namespace
register_payment_requirements()  : mixed
Registers and validates payment requirements callbacks.
register_update_callback()  : mixed
Add callback functions that can be executed by the cart/extensions endpoint.
format_extensions_properties()  : array<string|int, mixed>
Format schema for an extension.
throw_exception()  : mixed
Throws error and/or silently logs it.

Properties

$endpoints

List of Store API schema that is allowed to be extended by extensions.

private array<string|int, string> $endpoints = [AutomatticWooCommerceStoreApiSchemasV1CartItemSchema::IDENTIFIER, AutomatticWooCommerceStoreApiSchemasV1CartSchema::IDENTIFIER, AutomatticWooCommerceStoreApiSchemasV1CheckoutSchema::IDENTIFIER, AutomatticWooCommerceStoreApiSchemasV1ProductSchema::IDENTIFIER]

Methods

get_endpoint_data()

Returns the registered endpoint data

public get_endpoint_data(string $endpoint[, array<string|int, mixed> $passed_args = [] ]) : object
Parameters
$endpoint : string

A valid identifier.

$passed_args : array<string|int, mixed> = []

Passed arguments from the Schema class.

Tags
throws
Exception

If a registered callback throws an error, or silently logs it.

Return values
objectReturns an casted object with registered endpoint data.

get_endpoint_schema()

Returns the registered endpoint schema

public get_endpoint_schema(string $endpoint[, array<string|int, mixed> $passed_args = [] ]) : object
Parameters
$endpoint : string

A valid identifier.

$passed_args : array<string|int, mixed> = []

Passed arguments from the Schema class.

Tags
throws
Exception

If a registered callback throws an error, or silently logs it.

Return values
objectReturns an array with registered schema data.

get_formatter()

Returns a formatter instance.

public get_formatter(string $name) : FormatterInterface
Parameters
$name : string

Formatter name.

Return values
FormatterInterface

get_payment_requirements()

Returns the additional payment requirements for the cart which are required to make payments. Values listed here are compared against each Payment Gateways "supports" flag.

public get_payment_requirements([array<string|int, mixed> $requirements = ['products'] ]) : array<string|int, mixed>
Parameters
$requirements : array<string|int, mixed> = ['products']

list of requirements that should be added to the collected requirements.

Tags
throws
Exception

If a registered callback throws an error, or silently logs it.

Return values
array<string|int, mixed>Returns a list of payment requirements.

get_update_callback()

Get callback for a specific endpoint and namespace.

public get_update_callback(string $namespace) : callable
Parameters
$namespace : string

The namespace to get callbacks for.

Tags
throws
Exception

When callback is not callable or parameters are incorrect.

Return values
callableThe callback registered by the extension.

register_endpoint_data()

Register endpoint data under a specified namespace

public register_endpoint_data(array<string|int, mixed> $args) : mixed
Parameters
$args : array<string|int, mixed>

{ An array of elements that make up a post to update or insert.

@type string   $endpoint Required. The endpoint to extend.
@type string   $namespace Required. Plugin namespace.
@type callable $schema_callback Callback executed to add schema data.
@type callable $data_callback Callback executed to add endpoint data.
@type string   $schema_type The type of data, object or array.

}

Tags
throws
Exception

On failure to register.

Return values
mixed

register_payment_requirements()

Registers and validates payment requirements callbacks.

public register_payment_requirements(array<string|int, mixed> $args) : mixed
Parameters
$args : array<string|int, mixed>

{ Array of registration data.

@type callable $data_callback Required. Callback executed to add payment requirements data.

}

Tags
throws
Exception

On failure to register.

Return values
mixed

register_update_callback()

Add callback functions that can be executed by the cart/extensions endpoint.

public register_update_callback(array<string|int, mixed> $args) : mixed
Parameters
$args : array<string|int, mixed>

{ An array of elements that make up the callback configuration.

@type string   $namespace Required. Plugin namespace.
@type callable $callback Required. The function/callable to execute.

}

Tags
throws
Exception

On failure to register.

Return values
mixed

format_extensions_properties()

Format schema for an extension.

private format_extensions_properties(string $namespace, array<string|int, mixed> $schema, string $schema_type) : array<string|int, mixed>
Parameters
$namespace : string

Error message or \Exception.

$schema : array<string|int, mixed>

An error to throw if we have debug enabled and user is admin.

$schema_type : string

How should data be shaped.

Return values
array<string|int, mixed>Formatted schema.

throw_exception()

Throws error and/or silently logs it.

private throw_exception(string|Throwable $exception_or_error) : mixed
Parameters
$exception_or_error : string|Throwable

Error message or \Exception.

Tags
throws
Exception

An error to throw if we have debug enabled and user is admin.

Return values
mixed