CheckoutLink
in package
Checkout Link class.
Table of Contents
- add_checkout_link_endpoint() : mixed
- Add the checkout link endpoint.
- add_query_vars() : array<string|int, mixed>
- Add the checkout link query var.
- handle_checkout_link_endpoint() : void
- Handle the checkout link endpoint.
- init() : mixed
- Initialize the checkout link service.
- add_error_notices() : void
- Add error notices to the cart.
- get_checkout_link() : string
- Process the query params and return the checkout link to redirect to complete with a cart link token.
- get_products_from_checkout_link() : array<string|int, array<string|int, mixed>>
- Get the products from the checkout link.
- parse_product_data() : array<string, string>
- Parse a semicolon-separated list of key-value pairs.
- validate_checkout_link() : bool
- Validate the checkout link.
- get_product_options_url() : string
- Get the product page URL where the shopper can choose the attributes missing from a checkout link.
- is_missing_variation_data_error() : bool
- Check if an add to cart error was caused by missing variation attributes.
- split_escaped() : array<string|int, string>
- Split a string on unescaped delimiters.
Methods
add_checkout_link_endpoint()
Add the checkout link endpoint.
public
add_checkout_link_endpoint() : mixed
Return values
mixed —add_query_vars()
Add the checkout link query var.
public
add_query_vars(array<string|int, mixed> $vars) : array<string|int, mixed>
Parameters
- $vars : array<string|int, mixed>
-
The query vars.
Return values
array<string|int, mixed> — The query vars.handle_checkout_link_endpoint()
Handle the checkout link endpoint.
public
handle_checkout_link_endpoint() : void
Return values
void —init()
Initialize the checkout link service.
public
init() : mixed
Return values
mixed —add_error_notices()
Add error notices to the cart.
protected
add_error_notices(WP_Error $errors) : void
Parameters
- $errors : WP_Error
-
The errors.
Return values
void —get_checkout_link()
Process the query params and return the checkout link to redirect to complete with a cart link token.
protected
get_checkout_link() : string
Return values
string — The checkout link.get_products_from_checkout_link()
Get the products from the checkout link.
protected
get_products_from_checkout_link() : array<string|int, array<string|int, mixed>>
Products use the format id-or-sku:quantity:variation-data:cart-item-data. Quantity and both data groups are optional,
while an empty variation group separates cart item data. Multiple key-value pairs within a data group use semicolons.
Prefix numeric SKUs with sku=. Delimiters within identifiers, keys, or values must be escaped with a tilde.
Return values
array<string|int, array<string|int, mixed>> — Array of product data formatted for CartController::add_to_cart().parse_product_data()
Parse a semicolon-separated list of key-value pairs.
protected
parse_product_data(string $raw_data) : array<string, string>
Parameters
- $raw_data : string
-
Raw product data from the checkout link.
Tags
Return values
array<string, string> — Sanitized product data.validate_checkout_link()
Validate the checkout link.
protected
validate_checkout_link() : bool
Return values
bool — True if the checkout link is valid, false otherwise.get_product_options_url()
Get the product page URL where the shopper can choose the attributes missing from a checkout link.
private
get_product_options_url(WC_Product $product, array<string|int, array<string|int, mixed>> $variation) : string
Attributes set by the variation, or passed in the link, are added to the URL so they are preselected.
Parameters
- $product : WC_Product
-
The variable product or variation from the checkout link.
- $variation : array<string|int, array<string|int, mixed>>
-
Variation attributes parsed from the checkout link.
Return values
string — The product page URL, or an empty string if the product page is not available.is_missing_variation_data_error()
Check if an add to cart error was caused by missing variation attributes.
private
is_missing_variation_data_error(Exception $exception) : bool
Parameters
- $exception : Exception
-
The add to cart exception.
Return values
bool —split_escaped()
Split a string on unescaped delimiters.
private
split_escaped(string $value, string $delimiter[, int $limit = PHP_INT_MAX ]) : array<string|int, string>
Parameters
- $value : string
-
Value to split.
- $delimiter : string
-
Single-character delimiter.
- $limit : int = PHP_INT_MAX
-
Maximum number of returned segments.
