WooCommerce Code Reference

WC_REST_Paypal_Standard_Controller extends WC_REST_Controller
in package

REST API PayPal Standard controller class.

Tags
extends

WC_REST_Controller

Table of Contents

$namespace  : string
Endpoint namespace.
$rest_base  : string
Route base.
$_fields  : null|array<string|int, mixed>
Used to cache computed return fields.
$_request  : null|WP_REST_Request
Used to verify if cached fields are for correct request object.
batch_items()  : array<string|int, mixed>
Bulk create, update and delete items.
get_endpoint_args_for_item_schema()  : array<string|int, mixed>
Compatibility functions for WP 5.5, since custom types are not supported anymore.
get_fields_for_response()  : array<string|int, mixed>
Gets an array of fields to be included on the response.
get_public_batch_schema()  : array<string|int, mixed>
Get the batch schema, conforming to JSON Schema.
process_shipping_callback()  : WP_REST_Response
Callback for when the customer updates their shipping details in PayPal.
register_routes()  : void
Register the routes for PayPal Standard REST API requests.
validate_setting_checkbox_field()  : string|WP_Error
Validate checkbox based settings.
validate_setting_image_width_field()  : string|WP_Error
Validate image_width based settings.
validate_setting_multiselect_field()  : array<string|int, mixed>|WP_Error
Validate multiselect based settings.
validate_setting_radio_field()  : string|WP_Error
Validate radio based settings.
validate_setting_select_field()  : string|WP_Error
Validate select based settings.
validate_setting_text_field()  : string
Validate a text value for a text based setting.
validate_setting_textarea_field()  : string
Validate textarea based settings.
validate_shipping_callback_request()  : bool
Validate the shipping callback request.
add_additional_fields_schema()  : array<string|int, mixed>
Add the schema from additional fields to an schema array.
add_meta_query()  : array<string|int, mixed>
Add meta query.
adjust_wp_5_5_datatype_compatibility()  : mixed
Change datatypes `date-time` to string, and `mixed` to composite of all built in types. This is required for maintaining forward compatibility with WP 5.5 since custom post types are not supported anymore.
check_batch_limit()  : bool|WP_Error
Check batch limit.
get_meta_data_for_response()  : array<string|int, mixed>
Limit the contents of the meta_data property based on certain request parameters.
get_normalized_rest_base()  : string
Get normalized rest base.
decode_meta_values()  : array<string|int, mixed>
Helper method to support recursively ensuring metadata string values are decoded.
get_order_shipping_rate_id()  : string
Get the shipping rate id from the order.
get_update_shipping_error_response()  : array<string|int, mixed>
Get the error response for the update shipping request.
get_updated_shipping_options()  : array<string|int, mixed>
Get the shipping options for the order.
get_variation_attributes_from_order_item()  : array<string|int, mixed>
Get the variation attributes stored in an order item's meta, in the format expected by WC_Cart::add_to_cart(). This mirrors the attribute handling in {@see WC_Cart_Session::populate_cart_from_order()}.
rebuild_cart_from_order()  : void
Rebuild the session cart.
update_order_shipping_address()  : void
Update the WooCommerce order with the new shipping address.
update_shipping_method_and_totals_for_order()  : void
Update the shipping method for the order, and then recompute the order totals.

Properties

Methods

batch_items()

Bulk create, update and delete items.

public batch_items(WP_REST_Request $request) : array<string|int, mixed>
Parameters
$request : WP_REST_Request

Full details about the request.

Return values
array<string|int, mixed> — Of WP_Error or WP_REST_Response.

get_endpoint_args_for_item_schema()

Compatibility functions for WP 5.5, since custom types are not supported anymore.

public get_endpoint_args_for_item_schema([string $method = WP_REST_Server::CREATABLE ]) : array<string|int, mixed>

See @link https://core.trac.wordpress.org/changeset/48306

Parameters
$method : string = WP_REST_Server::CREATABLE

Optional. HTTP method of the request.

Return values
array<string|int, mixed> — Endpoint arguments.

get_fields_for_response()

Gets an array of fields to be included on the response.

public get_fields_for_response(WP_REST_Request $request) : array<string|int, mixed>

Included fields are based on item schema and _fields= request argument. Updated from WordPress 5.3, included into this class to support old versions.

Parameters
$request : WP_REST_Request

Full details about the request.

Tags
since
3.5.0
Return values
array<string|int, mixed> — Fields to be included in the response.

process_shipping_callback()

Callback for when the customer updates their shipping details in PayPal.

public process_shipping_callback(WP_REST_Request $request) : WP_REST_Response

https://developer.paypal.com/docs/checkout/standard/customize/shipping-module/#server-side-shipping-callbacks

Parameters
$request : WP_REST_Request

The request object.

Return values
WP_REST_Response — The response object.

validate_setting_checkbox_field()

Validate checkbox based settings.

public validate_setting_checkbox_field(string $value, array<string|int, mixed> $setting) : string|WP_Error
Parameters
$value : string

Value.

$setting : array<string|int, mixed>

Setting.

Tags
since
3.0.0
Return values
string|WP_Error —

validate_setting_image_width_field()

Validate image_width based settings.

public validate_setting_image_width_field(array<string|int, mixed> $values, array<string|int, mixed> $setting) : string|WP_Error
Parameters
$values : array<string|int, mixed>

Values.

$setting : array<string|int, mixed>

Setting.

Tags
since
3.0.0
Return values
string|WP_Error —

validate_setting_multiselect_field()

Validate multiselect based settings.

public validate_setting_multiselect_field(array<string|int, mixed> $values, array<string|int, mixed> $setting) : array<string|int, mixed>|WP_Error
Parameters
$values : array<string|int, mixed>

Values.

$setting : array<string|int, mixed>

Setting.

Tags
since
3.0.0
Return values
array<string|int, mixed>|WP_Error —

validate_setting_radio_field()

Validate radio based settings.

public validate_setting_radio_field(string $value, array<string|int, mixed> $setting) : string|WP_Error
Parameters
$value : string

Value.

$setting : array<string|int, mixed>

Setting.

Tags
since
3.0.0
Return values
string|WP_Error —

validate_setting_select_field()

Validate select based settings.

public validate_setting_select_field(string $value, array<string|int, mixed> $setting) : string|WP_Error
Parameters
$value : string

Value.

$setting : array<string|int, mixed>

Setting.

Tags
since
3.0.0
Return values
string|WP_Error —

validate_setting_text_field()

Validate a text value for a text based setting.

public validate_setting_text_field(string $value, array<string|int, mixed> $setting) : string
Parameters
$value : string

Value.

$setting : array<string|int, mixed>

Setting.

Tags
since
3.0.0
Return values
string —

validate_setting_textarea_field()

Validate textarea based settings.

public validate_setting_textarea_field(string $value, array<string|int, mixed> $setting) : string
Parameters
$value : string

Value.

$setting : array<string|int, mixed>

Setting.

Tags
since
3.0.0
since
9.0.0

No longer allows storing IFRAME, which was allowed for "ShareThis" integration no longer found in core.

Return values
string —

validate_shipping_callback_request()

Validate the shipping callback request.

public validate_shipping_callback_request(WP_REST_Request<string|int, array<string, mixed>> $request) : bool
Parameters
$request : WP_REST_Request<string|int, array<string, mixed>>

The request object.

Tags
since
10.6.0
Return values
bool — True if the request is valid, false otherwise.

add_additional_fields_schema()

Add the schema from additional fields to an schema array.

protected add_additional_fields_schema(array<string|int, mixed> $schema) : array<string|int, mixed>

The type of object is inferred from the passed schema.

Parameters
$schema : array<string|int, mixed>

Schema array.

Return values
array<string|int, mixed> —

add_meta_query()

Add meta query.

protected add_meta_query(array<string|int, mixed> $args, array<string|int, mixed> $meta_query) : array<string|int, mixed>
Parameters
$args : array<string|int, mixed>

Query args.

$meta_query : array<string|int, mixed>

Meta query.

Tags
since
3.0.0
Return values
array<string|int, mixed> —

adjust_wp_5_5_datatype_compatibility()

Change datatypes `date-time` to string, and `mixed` to composite of all built in types. This is required for maintaining forward compatibility with WP 5.5 since custom post types are not supported anymore.

protected adjust_wp_5_5_datatype_compatibility(array<string|int, mixed> $endpoint_args) : mixed

See @link https://core.trac.wordpress.org/changeset/48306

We still use the 'mixed' type, since if we convert to composite type everywhere, it won't work in 5.4 anymore because they require to define the full schema.

Parameters
$endpoint_args : array<string|int, mixed>

Schema with datatypes to convert.

Return values
mixed — Schema with converted datatype.

get_meta_data_for_response()

Limit the contents of the meta_data property based on certain request parameters.

protected get_meta_data_for_response(WP_REST_Request $request, array<string|int, mixed> $meta_data) : array<string|int, mixed>

Note that if both include_meta and exclude_meta are present in the request, include_meta will take precedence.

Parameters
$request : WP_REST_Request

The request.

$meta_data : array<string|int, mixed>

All of the meta data for an object.

Return values
array<string|int, mixed> —

decode_meta_values()

Helper method to support recursively ensuring metadata string values are decoded.

private decode_meta_values(array<string|int, mixed> $meta_value_array, string $blog_charset) : array<string|int, mixed>
Parameters
$meta_value_array : array<string|int, mixed>

The metadata value array.

$blog_charset : string

The blog charset.

Return values
array<string|int, mixed> — The decoded metadata value array.

get_update_shipping_error_response()

Get the error response for the update shipping request.

private get_update_shipping_error_response([string $issue = 'ADDRESS_ERROR' ]) : array<string|int, mixed>
Parameters
$issue : string = 'ADDRESS_ERROR'

The issue with the shipping address.

Return values
array<string|int, mixed> — The error response.

get_updated_shipping_options()

Get the shipping options for the order.

private get_updated_shipping_options(WC_Order $order, array<string|int, mixed> $selected_shipping_option, string|null &$updated_shipping_option_id) : array<string|int, mixed>
Parameters
$order : WC_Order

The order object.

$selected_shipping_option : array<string|int, mixed>

The selected shipping option.

$updated_shipping_option_id : string|null

The updated shipping option id after the updates.

Return values
array<string|int, mixed> — The shipping options.

get_variation_attributes_from_order_item()

Get the variation attributes stored in an order item's meta, in the format expected by WC_Cart::add_to_cart(). This mirrors the attribute handling in {@see WC_Cart_Session::populate_cart_from_order()}.

private get_variation_attributes_from_order_item(WC_Order_Item_Product $item, int $product_id) : array<string|int, mixed>
Parameters
$item : WC_Order_Item_Product

The order item.

$product_id : int

The ID of the parent variable product.

Return values
array<string|int, mixed> — Attribute values keyed by 'attribute_{name}'.