Skip to content
Docs
Get RestroPress

Function

Checkout experience functions

Updated
On this page

Functions for the reworked checkout: the sticky Place order bar, inline field errors and the order summary.

9 functions. Each entry shows the signature, parameters, return value and where it is defined. Functions marked internal are hook callbacks, screen renderers and other plumbing that extensions normally do not call.

rpress_checkout_ux_resolve_service()#

Resolves the service type a minimum order applies to.

Uses the requested slug, then the service_type cookie, then the default enabled service. A slug that is not enabled falls back to the default.

rpress_checkout_ux_resolve_service( $requested = '' )

Parameters

ParameterTypeDefaultDescription
$requestedstring''Optional service slug sent by the browser.

Returns string: A service slug, or an empty string when no service is enabled.

Example

$service = rpress_checkout_ux_resolve_service();

Defined in includes/features/checkout-ux/functions.php, line 22.

rpress_checkout_ux_format_amount()#

Formats an amount as plain text with HTML entities decoded.

Uses rpress_currency_filter() and rpress_format_amount(), then decodes entities so the result is safe for JavaScript .text().

rpress_checkout_ux_format_amount( $amount )

Parameters

ParameterTypeDefaultDescription
$amountfloatRequiredAmount.

Returns string: The formatted amount.

Example

$text = rpress_checkout_ux_format_amount( 12.5 );

Defined in includes/features/checkout-ux/functions.php, line 43.

rpress_checkout_ux_minimum_order()#

Returns the minimum order state for a service and cart subtotal.

Uses the allow_minimum_order setting, minimum_order_price for delivery and minimum_order_price_pickup for pickup; other services have no minimum. Filterable through rpress_checkout_ux_minimum_order.

rpress_checkout_ux_minimum_order( $service, $subtotal = null )

Parameters

ParameterTypeDefaultDescription
$servicestringRequiredService slug, delivery or pickup.
$subtotalfloat|nullnullCart subtotal; null reads the live cart.

Returns array: Array with enabled, service, minimum, subtotal, shortfall, below, minimum_formatted, shortfall_formatted, message and detail.

Example

$min = rpress_checkout_ux_minimum_order( 'delivery' );
if ( $min['below'] ) {
	echo esc_html( $min['message'] );
}

Defined in includes/features/checkout-ux/functions.php, line 71.

rpress_checkout_ux_state()#

Returns a snapshot of the live cart for the checkout scripts.

Includes the resolved service and its label, cart quantity, subtotal, total, formatted total and the minimum order state.

rpress_checkout_ux_state( $service = '' )

Parameters

ParameterTypeDefaultDescription
$servicestring''Optional requested service slug.

Returns array: Array with service, service_label, quantity, subtotal, total, total_formatted and minimum.

Example

$state = rpress_checkout_ux_state();
$total = $state['total_formatted'];

Defined in includes/features/checkout-ux/functions.php, line 132.

rpress_checkout_ux_required_address_fields()#

Returns the delivery address fields the checkout marks as required, with their error messages.

Reads rp_get_checkout_fields() and keeps fields that are required and not hidden.

rpress_checkout_ux_required_address_fields()

Returns array: Field name => error message.

Internal. Defined in includes/features/checkout-ux/functions.php, line 156.

rpress_checkout_ux_should_load()#

Checks whether the checkout UX assets should load on this request.

True on the checkout page, and on other front-end pages when allow_minimum_order is set and the rp-frontend script is enqueued. Filterable through rpress_checkout_ux_should_load.

rpress_checkout_ux_should_load()

Returns bool: True when the assets load.

Internal. Defined in includes/features/checkout-ux/hooks.php, line 21.

rpress_checkout_ux_enqueue()#

Enqueues the checkout UX script and stylesheet.

Runs on wp_enqueue_scripts at priority 30 and passes data to the script as rpress_checkout_ux, filterable through rpress_checkout_ux_vars. The cart state is embedded only on the checkout page.

rpress_checkout_ux_enqueue()

Internal. Defined in includes/features/checkout-ux/hooks.php, line 48.

rpress_checkout_ux_ajax_state()#

Handles the AJAX request for the current cart state for a service.

Read-only. Requires the rpress-checkout-ux nonce in the security field (403 otherwise). Available to logged-out visitors.

rpress_checkout_ux_ajax_state()

Internal. Defined in includes/features/checkout-ux/hooks.php, line 131.

rpress_checkout_ux_service_switch_response()#

Adds the cart state to the delivery and pickup switch response.

Hooked to rpress_checkout_update_service_option_response. Adds the state under the checkout_ux key.

rpress_checkout_ux_service_switch_response( $data )

Parameters

ParameterTypeDefaultDescription
$dataarrayRequiredResponse data.

Returns array: The data, with checkout_ux added.

Internal. Defined in includes/features/checkout-ux/hooks.php, line 150.

Was this page helpful?