CartItem extends AbstractCart
in package

Cart Item Route

Handles adding products to cart and removing items Used by express checkout methods on product pages

Tags
since
4.0.0

Table of Contents

Properties

$transformer  : DataTransformer

Methods

__construct()  : mixed
get_error_response()  : WP_Error
Convert exceptions/WP_Error to error responses
get_full_path()  : string
Get full path including namespace
get_namespace()  : string
Get the route namespace
get_path()  : string
Get the route path
get_routes()  : array<string|int, mixed>
Get route configuration
handle_delete_request()  : array<string|int, mixed>|WP_Error
Handle DELETE request - Remove item from cart
handle_get_request()  : mixed
Handle GET request
handle_post_request()  : array<string|int, mixed>|WP_Error
Handle POST request - Add item to cart
handle_put_request()  : mixed
Handle PUT request
handle_request()  : WP_REST_Response|WP_Error
Handle REST request
validate_payment_method()  : bool
Validate payment method
calculate_totals()  : void
Calculate cart totals
clear_cached_shipping_rates()  : void
Clear cached shipping rates
get_payment_method_from_request()  : WC_Payment_Gateway|null
Get payment gateway from request
get_wc_notice()  : string
Get WooCommerce notice
populate_post_data()  : mixed
Populate $_POST and $_REQUEST with request data

Properties

Methods

get_error_response()

Convert exceptions/WP_Error to error responses

public get_error_response(Exception|WP_Error $error) : WP_Error
Parameters
$error : Exception|WP_Error
Return values
WP_Error

handle_delete_request()

Handle DELETE request - Remove item from cart

public handle_delete_request(WP_REST_Request $request) : array<string|int, mixed>|WP_Error
Parameters
$request : WP_REST_Request
Return values
array<string|int, mixed>|WP_Error

handle_get_request()

Handle GET request

public handle_get_request(WP_REST_Request $request) : mixed
Parameters
$request : WP_REST_Request
Tags
throws
Exception

handle_post_request()

Handle POST request - Add item to cart

public handle_post_request(WP_REST_Request $request) : array<string|int, mixed>|WP_Error
Parameters
$request : WP_REST_Request
Return values
array<string|int, mixed>|WP_Error

handle_put_request()

Handle PUT request

public handle_put_request(WP_REST_Request $request) : mixed
Parameters
$request : WP_REST_Request
Tags
throws
Exception

handle_request()

Handle REST request

public handle_request(WP_REST_Request $request) : WP_REST_Response|WP_Error

Routes to appropriate method handler based on HTTP method

Parameters
$request : WP_REST_Request
Return values
WP_REST_Response|WP_Error

validate_payment_method()

Validate payment method

public validate_payment_method(string $payment_method, WP_REST_Request $request) : bool
Parameters
$payment_method : string

Payment method ID

$request : WP_REST_Request

Request object

Return values
bool

clear_cached_shipping_rates()

Clear cached shipping rates

protected clear_cached_shipping_rates() : void

Forces WooCommerce to recalculate shipping rates

get_payment_method_from_request()

Get payment gateway from request

protected get_payment_method_from_request(WP_REST_Request $request) : WC_Payment_Gateway|null
Parameters
$request : WP_REST_Request
Return values
WC_Payment_Gateway|null

get_wc_notice()

Get WooCommerce notice

protected get_wc_notice([string $notice_type = '' ][, string $default = '' ]) : string
Parameters
$notice_type : string = ''

Notice type (error, success, notice)

$default : string = ''

Default message if no notice found

Return values
string

populate_post_data()

Populate $_POST and $_REQUEST with request data

protected populate_post_data(WP_REST_Request $request) : mixed

Some 3rd party plugins depend on $_POST being populated

Parameters
$request : WP_REST_Request

        
On this page

Search results