Skip to content
Docs
Get RestroPress

Function

Cart functions

Updated
On this page

Functions for reading and changing the cart: adding, removing and updating menu items, totals, discounts and cart messages.

75 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_add_rewrite_endpoints()#

Registers the rpress-add and rpress-remove rewrite endpoints.

Hooked to init. The endpoints back the /rpress-add/<id> and /rpress-remove/<cart_key> URLs handled by rpress_process_cart_endpoints().

rpress_add_rewrite_endpoints( $rewrite_rules )

Parameters

ParameterTypeDefaultDescription
$rewrite_rulesmixedRequiredUnused. init passes no arguments.

Note: The parameter is not used by the function.

Internal. Defined in includes/cart/actions.php, line 21.

rpress_process_cart_endpoints()#

Handles /rpress-add/<id> and /rpress-remove/<cart_key> requests and redirects to checkout.

Hooked to template_redirect at priority 100. For rpress-add it adds the menu item with no options; for rpress-remove it removes the cart line with that key. Both then redirect to the checkout page and stop execution.

rpress_process_cart_endpoints()

Note: Ends the request with a redirect.

Internal. Defined in includes/cart/actions.php, line 35.

rpress_process_add_to_cart()#

Handles the add_to_cart action: adds a menu item to the cart and redirects.

Runs on the rpress_add_to_cart action (triggered by a request with rpress_action=add_to_cart). Reads fooditem_id, rpress_options and fooditem_qty from the request data, calls rpress_add_to_cart(), then redirects to the checkout page (303) when the redirect-on-add setting is on and the visitor is not already on checkout, or back to the current URL without the action arguments.

rpress_process_add_to_cart( $data )

Parameters

ParameterTypeDefaultDescription
$dataarrayRequiredRequest data (the $_GET or $_POST array) with fooditem_id and optionally rpress_options, fooditem_qty and rpress_fooditem_quantity_<price_id>.

Note: Ends the request with a redirect.

Internal. Defined in includes/cart/actions.php, line 58.

rpress_process_remove_from_cart()#

Handles the remove action: removes the cart line given by the cart_item query argument and redirects.

Runs on the rpress_remove action. The cart key is read from $_GET['cart_item']; the $data argument is not used. After removal it redirects to the current URL without rpress_action, cart_item and nocache.

rpress_process_remove_from_cart( $data )

Parameters

ParameterTypeDefaultDescription
$dataarrayRequiredRequest data passed by the action dispatcher. Not used.

Note: Ends the request with a redirect.

Internal. Defined in includes/cart/actions.php, line 91.

rpress_process_remove_fee_from_cart()#

Handles the remove_fee action: removes a fee from the cart and redirects.

Runs on the rpress_remove_fee action. Removes the fee named in $data['fee'] via the fees class, then redirects to the current URL without rpress_action, fee and nocache.

rpress_process_remove_fee_from_cart( $data )

Parameters

ParameterTypeDefaultDescription
$dataarrayRequiredRequest data with a fee key holding the fee ID.

Note: Ends the request with a redirect.

Internal. Defined in includes/cart/actions.php, line 104.

rpress_process_collection_purchase()#

Handles the purchase_collection action: adds all menu items of a taxonomy term to the cart.

Runs on the rpress_purchase_collection action. Reads taxonomy and terms from the request data, calls rpress_add_collection_to_cart(), and redirects to the current URL with added=1.

rpress_process_collection_purchase( $data )

Parameters

ParameterTypeDefaultDescription
$dataarrayRequiredRequest data with taxonomy and terms keys (URL-encoded).

Note: Ends the request with a redirect.

Internal. Defined in includes/cart/actions.php, line 117.

rpress_process_cart_update()#

Handles the update_cart action: applies submitted quantities to the cart lines.

Runs on the rpress_update_cart action. For each entry in $data['rpress-cart-fooditems'] it reads the matching rpress-cart-fooditem-<key>-options (JSON) and rpress-cart-fooditem-<key>-quantity values and calls rpress_set_cart_item_quantity() with the cart key. Does not redirect.

rpress_process_cart_update( $data )

Parameters

ParameterTypeDefaultDescription
$dataarrayRequiredRequest data from the cart form.

Internal. Defined in includes/cart/actions.php, line 130.

rpress_process_cart_save()#

Handles the save_cart action: saves the cart and redirects to checkout if saving fails.

Runs on the rpress_save_cart action. Calls rpress_save_cart(); when it returns false, redirects to the checkout page and exits.

rpress_process_cart_save( $data )

Parameters

ParameterTypeDefaultDescription
$dataarrayRequiredRequest data passed by the action dispatcher. Not used.

Internal. Defined in includes/cart/actions.php, line 144.

rpress_process_cart_restore()#

Handles the restore_cart action: restores a saved cart and redirects to checkout.

Runs on the rpress_restore_cart action. Calls rpress_restore_cart() and redirects to the checkout page and exits unless a WP_Error was returned.

rpress_process_cart_restore( $data )

Parameters

ParameterTypeDefaultDescription
$dataarrayRequiredRequest data passed by the action dispatcher. Not used.

Internal. Defined in includes/cart/actions.php, line 157.

rpress_get_cart_contents()#

Returns the cart lines, dropping menu items that no longer exist or cannot be purchased.

Loads the cart from the session on first use, removes lines whose menu item is missing or unavailable (and saves the cleaned cart back to the session), then applies the rpress_cart_contents filter and fires rpress_cart_contents_loaded. Keys are re-indexed from 0.

rpress_get_cart_contents()

Returns array: List of cart lines. Each line is an array that includes at least id and quantity, and may include price, price_id, addon_items and instruction. Empty array when the cart is empty.

Example

foreach ( rpress_get_cart_contents() as $cart_key => $line ) {
	error_log( sprintf( 'Line %d: item %d x %d', $cart_key, $line['id'], $line['quantity'] ) );
}

Defined in includes/cart/functions.php, line 20.

rpress_get_cart_content_details()#

Returns per-line price, discount, tax and fee details for the cart.

Calculates each line from the cart's current contents. Rows are keyed by cart key and contain name, id, item_number, item_price, quantity, discount, subtotal, tax, fees, price and addon_items.

rpress_get_cart_content_details()

Returns array|null: Array of line detail rows, or an empty array when the cart is empty. Returns null if a line has no menu item ID.

Example

foreach ( rpress_get_cart_content_details() as $cart_key => $row ) {
	error_log( $row['name'] . ': ' . $row['price'] );
}

Defined in includes/cart/functions.php, line 31.

rpress_get_cart_quantity()#

Returns the number of lines in the cart.

Counts cart lines, not the sum of line quantities: two lines each with quantity 3 return 2. The result passes through the rpress_get_cart_quantity filter.

rpress_get_cart_quantity()

Returns int: Number of cart lines.

Note: Counts lines, not the total of the quantity values.

Defined in includes/cart/functions.php, line 40.

rpress_add_to_cart()#

Adds a menu item to the cart, or raises the quantity of an identical existing line.

The $options array is stored as the cart line itself, so include id, quantity and price, plus price_id, addon_items and instruction when relevant (the AJAX add-to-cart handler builds its options this way). If an identical line (same menu item, price ID, add-ons and instruction) exists, its quantity is increased instead; the rpress_merge_identical_cart_items filter can turn this off. Returns early without adding when the post is not a menu item or cannot be purchased. Fires rpress_pre_add_to_cart and rpress_post_add_to_cart and clears checkout errors.

rpress_add_to_cart( $fooditem_id, $options = array() )

Parameters

ParameterTypeDefaultDescription
$fooditem_idintRequiredMenu item (fooditem) post ID.
$optionsarrayarray()Cart line data to store, including id, quantity, price, and optionally price_id, addon_items and instruction.

Returns int|null: Cart key of the added or merged line, or null when nothing was added.

Example

$item_id = 123;
$key = rpress_add_to_cart( $item_id, array(
	'id'          => $item_id,
	'quantity'    => 2,
	'price'       => rpress_get_fooditem_price( $item_id ),
	'instruction' => '',
) );

Note: The documented return of a string is wrong: the method returns an integer key or null.

Defined in includes/cart/functions.php, line 55.

rpress_remove_from_cart()#

Removes a line from the cart by its cart key.

Fires rpress_pre_remove_from_cart and rpress_post_remove_from_cart, re-indexes the remaining lines, saves the cart to the session and clears checkout errors.

rpress_remove_from_cart( $cart_key )

Parameters

ParameterTypeDefaultDescription
$cart_keyintRequiredIndex of the line in the cart array.

Returns array: The updated cart lines.

Example

rpress_remove_from_cart( 0 ); // remove the first line

Defined in includes/cart/functions.php, line 65.

rpress_item_in_cart()#

Checks whether a menu item is in the cart.

Matches on menu item ID. When both $options and the cart line carry a price_id, they must match as well. The result passes through the rpress_item_in_cart filter.

rpress_item_in_cart( $fooditem_id = 0, $options = array() )

Parameters

ParameterTypeDefaultDescription
$fooditem_idint0Menu item (fooditem) post ID.
$optionsarrayarray()Optional options; only price_id is compared.

Returns bool: True when a matching line exists.

Example

if ( rpress_item_in_cart( 123 ) ) {
	// the item is already in the cart
}

Defined in includes/cart/functions.php, line 77.

rpress_get_item_position_in_cart()#

Returns the cart key of the first line matching a menu item and options.

Matches on menu item ID, then on price_id and the set of add-on IDs when those are present in $options. An options['cart_key'] that exists in the cart is returned directly.

rpress_get_item_position_in_cart( $fooditem_id = 0, $options = array() )

Parameters

ParameterTypeDefaultDescription
$fooditem_idint0Menu item (fooditem) post ID.
$optionsarrayarray()Optional match criteria: cart_key, price_id, addon_items (each with addon_id).

Returns int|string|false: The cart key of the matching line, or false when there is none.

Example

$position = rpress_get_item_position_in_cart( 123 );
if ( false !== $position ) {
	rpress_remove_from_cart( $position );
}

Defined in includes/cart/functions.php, line 89.

rpress_item_quantities_enabled()#

Checks whether per-item quantities are enabled in the settings.

Reads the item_quantities option and applies the rpress_item_quantities_enabled filter.

rpress_item_quantities_enabled()

Returns bool: True when item quantities are enabled.

Defined in includes/cart/functions.php, line 98.

rpress_set_cart_item_quantity()#

Sets the quantity, add-ons, price ID and instruction of a cart line.

With $cart_key set, it delegates to rpress_set_cart_item_quantity_by_key(). Otherwise it updates the first line matching the menu item and options, and returns the cart unchanged if none matches. Quantities below 1 become 1. The line's instruction, addon_items and price_id are overwritten from $options and become empty when absent. Fires rpress_after_set_cart_item_quantity.

rpress_set_cart_item_quantity( $fooditem_id = 0, $quantity = 1, $options = array(), $cart_key = null )

Parameters

ParameterTypeDefaultDescription
$fooditem_idint0Menu item (fooditem) post ID.
$quantityint1New quantity.
$optionsarrayarray()Line options: instruction, addon_items, price_id.
$cart_keyint|string|nullnullExact cart line to update; when given, $fooditem_id is not used for lookup.

Returns array: The updated cart contents.

Example

// Update line 0 to quantity 3, keeping no add-ons.
rpress_set_cart_item_quantity( 0, 3, array(), 0 );

Note: Passing $options without the existing add-ons or instruction clears them from the line. Pass $cart_key when the same menu item appears on more than one line.

Defined in includes/cart/functions.php, line 112.

rpress_set_cart_item_quantity_by_key()#

Updates one cart line, identified by its exact cart key.

Sets quantity (minimum 1) and overwrites instruction, addon_items and price_id from $options. Does nothing if the key is empty or does not exist. Fires rpress_after_set_cart_item_quantity.

rpress_set_cart_item_quantity_by_key( $cart_key = 0, $quantity = 1, $options = array() )

Parameters

ParameterTypeDefaultDescription
$cart_keyint|string0Cart line key.
$quantityint1New quantity.
$optionsarrayarray()Line options: instruction, addon_items, price_id.

Returns array: The cart contents.

Example

rpress_set_cart_item_quantity_by_key( 1, 2, array( 'instruction' => 'No onions' ) );

Note: Omitted options (add-ons, price ID, instruction) are cleared on the line.

Defined in includes/cart/functions.php, line 125.

rpress_get_cart_item_quantity()#

Returns the quantity of a menu item in the cart.

Finds the line with rpress_get_item_position_in_cart() and returns its quantity, at least 1, after the rpress_get_cart_item_quantity filter.

rpress_get_cart_item_quantity( $fooditem_id = 0, $options = array() )

Parameters

ParameterTypeDefaultDescription
$fooditem_idint0Menu item (fooditem) post ID.
$optionsarrayarray()Match criteria passed to the position lookup.

Returns int: Quantity of the line.

Defined in includes/cart/functions.php, line 136.

rpress_cart_item_price()#

Returns the formatted price of a cart item.

Calls rpress_get_cart_item_price() and formats the result with the store currency. $item must contain a price key. The result passes through the rpress_cart_item_price_label filter.

rpress_cart_item_price( $item_id = 0, $item = array(), $options = array() )

Parameters

ParameterTypeDefaultDescription
$item_idint0Menu item (fooditem) post ID.
$itemarrayarray()Cart line; must include price.
$optionsarrayarray()Options; price_id selects a variation.

Returns string: Currency-formatted price.

Defined in includes/cart/functions.php, line 149.

rpress_get_cart_item_price()#

Returns the base price of a menu item, excluding tax.

Uses the variation price when the menu item has variable prices and $price_id is not null, otherwise the menu item price. When prices include tax, the item tax is subtracted. Add-on prices are not included, and $remove_tax_from_inclusive and $item_subtotal are not used. For the final price after tax and discounts use rpress_get_cart_item_final_price().

rpress_get_cart_item_price( $fooditem_id = 0, $item = array(), $options = array(), $price_id = null, $remove_tax_from_inclusive = false, $item_subtotal = 0.00 )

Parameters

ParameterTypeDefaultDescription
$fooditem_idint0Menu item (fooditem) post ID.
$itemarrayarray()Cart line.
$optionsarrayarray()Options (not used in the calculation).
$price_idint|nullnullVariable price ID.
$remove_tax_from_inclusiveboolfalseNot used.
$item_subtotalfloat0.00Not used.

Returns float: Price of the item.

Defined in includes/cart/functions.php, line 166.

rpress_get_cart_item_final_price()#

Returns the price of a cart line after taxes and discounts.

Reads the price of the row from the cart details, then applies the rpress_cart_item_final_price filter.

rpress_get_cart_item_final_price( $item_key = 0 )

Parameters

ParameterTypeDefaultDescription
$item_keyint0Cart line key.

Returns float: Final price for the line.

Note: Reads the cart details calculated by rpress_get_cart_content_details(); call that first (or any function that does) or the row may not exist.

Defined in includes/cart/functions.php, line 178.

rpress_get_cart_item_tax()#

Calculates the tax for a cart item.

Returns 0 when the menu item is tax exclusive. Otherwise it calculates tax on $subtotal using the country and state posted in billing_country and card_state, if any. The value passes through the rpress_get_cart_item_tax filter.

rpress_get_cart_item_tax( $fooditem_id = 0, $options = array(), $subtotal = '' )

Parameters

ParameterTypeDefaultDescription
$fooditem_idint0Menu item (fooditem) post ID.
$optionsarrayarray()Cart line data (passed to the filter as the item).
$subtotalfloat|string''Amount to calculate tax on.

Returns float: Tax amount, never negative.

Defined in includes/cart/functions.php, line 190.

rpress_get_price_name()#

Returns the name of a variable price option for a menu item.

Returns false unless the menu item has variable prices and $options is not empty. Looks up $options['price_id'] and applies the rpress_get_price_name filter.

rpress_get_price_name( $fooditem_id = 0, $options = array() )

Parameters

ParameterTypeDefaultDescription
$fooditem_idint0Menu item (fooditem) post ID.
$optionsarrayarray()Must contain price_id.

Returns string|false: Price option name, or false.

Defined in includes/cart/functions.php, line 205.

rpress_get_cart_item_price_id()#

Returns the variable price ID stored on a cart item.

Looks for price_id in item_number, item_number.options, options or the item itself, in that order.

rpress_get_cart_item_price_id( $item = array() )

Parameters

ParameterTypeDefaultDescription
$itemarrayarray()Cart line or cart details row.

Returns int|string|null: Price ID, or null when none is set.

Defined in includes/cart/functions.php, line 226.

rpress_get_cart_item_price_name()#

Returns the variable price name for a cart item.

Resolves the item's price ID and looks up the matching name in the menu item's variable prices. Applies the rpress_get_cart_item_price_name filter.

rpress_get_cart_item_price_name( $item = array() )

Parameters

ParameterTypeDefaultDescription
$itemarrayarray()Cart line; must include id.

Returns string: Price name, or an empty string.

Defined in includes/cart/functions.php, line 236.

rpress_get_cart_item_name()#

Returns the display title of a cart item.

Uses the post title, falling back to the ID, and appends ' - <price name>' for menu items with variable prices. Applies the rpress_get_cart_item_name filter.

rpress_get_cart_item_name( $item = array() )

Parameters

ParameterTypeDefaultDescription
$itemarrayarray()Cart line; must include id.

Returns string: Item title.

Example

foreach ( rpress_get_cart_contents() as $line ) {
	echo esc_html( rpress_get_cart_item_name( $line ) );
}

Defined in includes/cart/functions.php, line 246.

rpress_cart_subtotal()#

Returns the cart subtotal before tax as a formatted, escaped string.

Formats the value of rpress_get_cart_subtotal() with the store currency and escapes it with esc_html(). Does not echo.

rpress_cart_subtotal()

Returns string: Formatted subtotal.

Note: Returns the formatted string; the documented float return is wrong.

Defined in includes/cart/functions.php, line 257.

rpress_get_cart_subtotal()#

Returns the cart subtotal before tax and discounts.

Sums the subtotal of each row from the cart details and applies the rpress_get_cart_subtotal filter.

rpress_get_cart_subtotal()

Returns float: Subtotal.

Example

$subtotal = rpress_get_cart_subtotal();

Defined in includes/cart/functions.php, line 269.

rpress_get_cart_discountable_subtotal()#

Returns the cart subtotal excluding items the discount does not apply to.

Sums the cart lines whose menu item is not in the discount's excluded products. Applies the rpress_get_cart_discountable_subtotal filter.

rpress_get_cart_discountable_subtotal( $code_id )

Parameters

ParameterTypeDefaultDescription
$code_idintRequiredDiscount ID.

Returns float: Discountable subtotal.

Defined in includes/cart/functions.php, line 277.

rpress_get_cart_items_subtotal()#

Sums the subtotal column of a set of cart detail rows.

Negative sums become 0. Applies the rpress_get_cart_items_subtotal filter.

rpress_get_cart_items_subtotal( $items )

Parameters

ParameterTypeDefaultDescription
$itemsarrayRequiredRows as returned by rpress_get_cart_content_details(), each with a subtotal.

Returns float: Items subtotal.

Defined in includes/cart/functions.php, line 286.

rpress_get_cart_total()#

Returns the cart total after discounts, tax and fees.

Adds the subtotal, tax and fees and subtracts discounts. A negative total, or one where subtotal minus discounts plus fees is not positive, becomes 0. Applies the rpress_get_cart_total filter and rounds to 2 decimals.

rpress_get_cart_total( $discounts = false )

Parameters

ParameterTypeDefaultDescription
$discountsarray|falsefalseDiscount codes to apply; false uses the codes stored in the session.

Returns float: Cart total.

Example

$total = rpress_get_cart_total();

Defined in includes/cart/functions.php, line 298.

rpress_cart_total()#

Returns or echoes the formatted cart total.

Formats the cart total with the store currency. With $echo true it prints the escaped value; with false it returns it. Applies the rpress_cart_total filter.

rpress_cart_total( $echo = true )

Parameters

ParameterTypeDefaultDescription
$echobooltrueWhether to print the total instead of returning it.

Returns string|null: Formatted total when $echo is false; null when printed.

Note: Echoes by default. Pass false to get the value.

Defined in includes/cart/functions.php, line 312.

rpress_cart_has_fees()#

Checks whether fees are applied to the cart.

Wraps the fees class has_fees(). For 'all' or 'fee', an empty cart is checked as type 'item'.

rpress_cart_has_fees( $type = 'all' )

Parameters

ParameterTypeDefaultDescription
$typestring'all'Fee type: 'all', 'fee' or 'item'.

Returns bool: True when at least one matching fee exists.

Defined in includes/cart/functions.php, line 328.

rpress_get_cart_fees()#

Returns the fees applied to the cart.

Reads the fees stored in the session. When the cart is empty only fees of type 'item' are returned. Passing a menu item ID limits the result to fees attached to that item.

rpress_get_cart_fees( $type = 'all', $fooditem_id = 0, $price_id = NULL )

Parameters

ParameterTypeDefaultDescription
$typestring'all'Fee type: 'all', 'fee' or 'item'.
$fooditem_idint0Limit to fees attached to this menu item.
$price_idint|nullnullWith $fooditem_id, limit to this price ID.

Returns array: Fees keyed by fee ID.

Example

foreach ( rpress_get_cart_fees() as $fee_id => $fee ) {
	echo esc_html( $fee['label'] . ': ' . $fee['amount'] );
}

Defined in includes/cart/functions.php, line 342.

rpress_get_cart_fee_total()#

Returns the total of the cart fees.

Adds the amount of every fee, skipping fees attached to a specific menu item. Applies the rpress_get_fee_total filter.

rpress_get_cart_fee_total()

Returns float: Total fees.

Defined in includes/cart/functions.php, line 354.

rpress_get_cart_fee_tax()#

Returns the tax charged on cart fees.

Calculates tax on each fee that is not flagged no_tax and has a non-negative amount, treating fee amounts as tax exclusive. Applies the rpress_get_cart_fee_tax filter.

rpress_get_cart_fee_tax()

Returns float: Tax on fees.

Defined in includes/cart/functions.php, line 364.

rpress_get_purchase_summary()#

Builds a short text summary of an order from its purchase data.

Joins the titles of the menu items in $purchase_data['fooditems'], optionally prefixed by the customer email. Applies the rpress_get_purchase_summary filter.

rpress_get_purchase_summary( $purchase_data, $email = true )

Parameters

ParameterTypeDefaultDescription
$purchase_dataarrayRequiredPurchase data with fooditems (each with id) and, when $email is true, user_email.
$emailbooltrueWhether to prefix the summary with the customer email.

Returns string: Summary text.

Defined in includes/cart/functions.php, line 378.

rpress_get_cart_tax()#

Returns the total tax for the cart.

Sums the tax of each cart line (0 when the subtotal is empty). With a flat discount applied, tax is recalculated on the discounted subtotal. The value is sanitized and passed through the rpress_get_cart_tax filter.

rpress_get_cart_tax()

Returns float: Total tax.

Defined in includes/cart/functions.php, line 398.

rpress_get_cart_tax_rate()#

Returns the tax rate used for the cart as a fraction.

Takes the rate from rpress_get_tax_rate() (the tax_rate option divided by 100) and applies the rpress_get_cart_tax_rate filter. In core the country and state are only passed to filters.

rpress_get_cart_tax_rate( $country = '', $state = '', $postal_code = '' )

Parameters

ParameterTypeDefaultDescription
$countrystring''Country code.
$statestring''State code.
$postal_codestring''Postal code; not used by core, passed to the filter.

Returns float: Tax rate, for example 0.1 for 10 percent.

Defined in includes/cart/functions.php, line 410.

rpress_cart_tax()#

Returns or echoes the formatted cart tax.

With $echo false it returns the currency-formatted tax; with true it prints it escaped. Applies the rpress_cart_tax filter.

rpress_cart_tax( $echo = false )

Parameters

ParameterTypeDefaultDescription
$echoboolfalseWhether to print the value instead of returning it.

Returns string|null: Formatted tax when $echo is false; null when printed.

Defined in includes/cart/functions.php, line 421.

rpress_add_collection_to_cart()#

Adds every menu item in a taxonomy term to the cart.

Queries all fooditem posts in the term (default get_posts status) and adds each with rpress_add_to_cart() and no options. Numeric $terms is treated as a term ID and converted to its slug.

rpress_add_collection_to_cart( $taxonomy, $terms )

Parameters

ParameterTypeDefaultDescription
$taxonomystringRequiredTaxonomy name.
$termsstring|int|arrayRequiredTerm slug, term ID, or array of slugs.

Returns array|false: Array of menu item IDs processed, or false if $taxonomy is not a string.

Note: Items are added with empty options, so the stored lines contain no id or price. Prefer adding with explicit options.

Defined in includes/cart/functions.php, line 438.

rpress_remove_item_url()#

Returns the URL that removes a cart line.

Builds a URL on the checkout page (during AJAX) or the current page, with cart_item and rpress_action=remove, plus a cache-busting argument. Applies the rpress_remove_item_url filter.

rpress_remove_item_url( $cart_key )

Parameters

ParameterTypeDefaultDescription
$cart_keyintRequiredCart line key.

Returns string: Removal URL.

Defined in includes/cart/functions.php, line 471.

rpress_remove_cart_fee_url()#

Returns the URL that removes a fee from the cart.

Builds a URL with fee, rpress_action=remove_fee and nocache arguments. Applies the rpress_remove_fee_url filter.

rpress_remove_cart_fee_url( $fee_id = '')

Parameters

ParameterTypeDefaultDescription
$fee_idstring''Fee ID.

Returns string: Removal URL.

Defined in includes/cart/functions.php, line 482.

rpress_empty_cart()#

Empties the cart and clears fees, discounts and any resumed payment.

Clears the rpress_cart, rpress_cart_fees and rpress_resume_payment session values, removes all discounts, and fires rpress_empty_cart.

rpress_empty_cart()

Example

rpress_empty_cart();

Defined in includes/cart/functions.php, line 492.

rpress_set_purchase_session()#

Stores purchase data in the session.

Saves the array under the rpress_purchase session key. Read it back with rpress_get_purchase_session().

rpress_set_purchase_session( $purchase_data = array() )

Parameters

ParameterTypeDefaultDescription
$purchase_dataarrayarray()Purchase data to store.

Defined in includes/cart/functions.php, line 506.

rpress_get_purchase_session()#

Returns the purchase data stored in the session.

Reads the rpress_purchase session key.

rpress_get_purchase_session()

Returns array|false: Stored purchase data, or false if none.

Defined in includes/cart/functions.php, line 519.

rpress_is_cart_saving_disabled()#

Checks whether cart saving is turned off.

Inverse of the enable_cart_saving option check.

rpress_is_cart_saving_disabled()

Returns bool: True when saving carts is disabled.

Defined in includes/cart/functions.php, line 528.

rpress_is_cart_saved()#

Checks whether a saved cart is available to restore.

False when cart saving is disabled or nothing is saved, or when the saved cart is identical to the current cart. Uses the rpress_saved_cart user meta for logged-in users and the rpress_saved_cart cookie for guests.

rpress_is_cart_saved()

Returns bool: True when a different saved cart exists.

Defined in includes/cart/functions.php, line 537.

rpress_save_cart()#

Saves the current cart so it can be restored later.

Does nothing and returns false when cart saving is disabled. Logged-in users get the rpress_saved_cart and rpress_cart_token user meta; guests get cookies of the same names for 7 days. Adds a success message, with a restore link, to the session rpress_cart_messages.

rpress_save_cart()

Returns bool: True when a cart was saved.

Note: Sets cookies for guests, so call it before any output is sent.

Defined in includes/cart/functions.php, line 546.

rpress_restore_cart()#

Restores a previously saved cart.

Returns false when cart saving is disabled. Validates the rpress_cart_token query argument against the stored token, loads the saved cart into the session, removes the saved copy, and queues a message in rpress_cart_messages.

rpress_restore_cart()

Returns bool|WP_Error: True on success, false when cart saving is disabled, or a WP_Error with code invalid_cart_token when the token does not match.

Defined in includes/cart/functions.php, line 555.

rpress_get_cart_token()#

Returns the stored token that validates saved-cart restore links.

Reads the rpress_cart_token user meta for logged-in users, or the cookie of the same name for guests. Applies the rpress_get_cart_token filter.

rpress_get_cart_token()

Returns string|false: Token, or false/empty when none exists.

Note: The documented int return is wrong; the token is a string.

Defined in includes/cart/functions.php, line 564.

rpress_delete_saved_carts()#

Cron callback that deletes saved carts older than one week.

Runs on rpress_weekly_scheduled_events and exits unless WordPress cron is running. Deletes the rpress_cart_token and rpress_saved_cart user meta of users whose token meta is older than a week.

rpress_delete_saved_carts()

Note: It reads the token meta value as a Unix timestamp, whereas rpress_generate_cart_token() returns a random hex string.

Internal. Defined in includes/cart/functions.php, line 576.

rpress_generate_cart_token()#

Generates a token for a saved-cart restore URL.

Returns a 64-character random hexadecimal string (falling back to wp_generate_password()). Applies the rpress_generate_cart_token filter.

rpress_generate_cart_token()

Returns string: Random token.

Note: The documented UNIX timestamp return is outdated; the value is a random string.

Defined in includes/cart/functions.php, line 620.

rpress_clear_service_cookies()#

Expires the service type, date and time cookies used by the old storefront UI.

Only acts when the old_ui_ux option is set. Hooked to rpress_empty_cart and rpress_complete_purchase. Clears service_type, service_time, service_time_text, service_date, delivery_date and service_date_manual.

rpress_clear_service_cookies()

Note: Sets cookies, so it only works before headers are sent.

Internal. Defined in includes/cart/functions.php, line 631.

rpress_clear_cookies_on_success_page()#

Clears the service cookies when the success page is displayed.

Hooked to template_redirect. Calls rpress_clear_service_cookies() if rpress_is_success_page() is true.

rpress_clear_cookies_on_success_page()

Internal. Defined in includes/cart/functions.php, line 663.

rpress_checkout_cart()#

Outputs the checkout cart block.

Registers the update-cart and save-cart footer buttons when those features are on, then prints a wrapper div around the checkout_cart template part. Fires rpress_before_checkout_cart, rpress_checkout_cart_top, rpress_checkout_cart_bottom and rpress_after_checkout_cart.

rpress_checkout_cart()

Note: Echoes output instead of returning it.

Defined in includes/cart/template.php, line 20.

rpress_shopping_cart()#

Outputs the cart template.

Loads the cart/cart template part. The $echo argument is not used and the template is always printed.

rpress_shopping_cart($echo = false)

Parameters

ParameterTypeDefaultDescription
$echoboolfalseNot used.

Note: Echoes output; $echo has no effect.

Defined in includes/cart/template.php, line 46.

rpress_get_cart_sidebar_summary_html()#

Returns the cart sidebar totals and checkout row markup.

Renders the cart/checkout template part and passes it through the rpress_cart_sidebar_summary_html filter. Returns an empty string when the cart is empty.

rpress_get_cart_sidebar_summary_html()

Returns string: HTML, or an empty string.

Defined in includes/cart/template.php, line 57.

rpress_cart_sidebar_hide_delivery_fee_on_pickup()#

Hides delivery fee rows in the cart sidebar for pickup orders.

Filter callback on rpress_cart_sidebar_render_fee. When the service_type cookie is pickup, it returns false for the delivery_fee fee and for any fee whose label contains 'delivery'.

rpress_cart_sidebar_hide_delivery_fee_on_pickup( $render, $fee_id, $fee )

Parameters

ParameterTypeDefaultDescription
$renderboolRequiredWhether the fee row will be rendered.
$fee_idstringRequiredFee ID.
$feearrayRequiredFee data, including label.

Returns bool: False to hide the row, otherwise the incoming value.

Internal. Defined in includes/cart/template.php, line 81.

rpress_get_cart_item_template()#

Builds the HTML for one cart line.

Loads the cart/item template part and replaces placeholders such as {item_title}, {item_qty}, {item_amount}, {addon_items}, {remove_url} and {special_instruction}. Returns null when $item has no id. Applies the rpress_cart_item filter.

rpress_get_cart_item_template($cart_key, $item, $ajax = false, $data_key = null)

Parameters

ParameterTypeDefaultDescription
$cart_keyintRequiredCart line key.
$itemarrayRequiredCart line. Quantity is read from options.quantity when options is set, otherwise quantity.
$ajaxboolfalseNot used.
$data_keyint|string|nullnullNot used.

Returns string|null: Line HTML, or null.

Defined in includes/cart/template.php, line 105.

rpress_edit_cart_item()#

Returns the cart key used by the edit link of a cart line.

rpress_edit_cart_item($cart_key, $item)

Parameters

ParameterTypeDefaultDescription
$cart_keyintRequiredCart line key.
$itemarrayRequiredCart line; not used.

Returns int: The cart key as an integer.

Internal. Defined in includes/cart/template.php, line 157.

get_addon_item_formatted()#

Builds the HTML list of add-ons for a cart line.

Reads addon_items from $addon_items['options'] or from the item itself, skips add-ons with no quantity, and outputs a ul with each add-on group term name (taxonomy addon_category) and price. Applies the rpress_cart_quantity_item filter.

get_addon_item_formatted($addon_items)

Parameters

ParameterTypeDefaultDescription
$addon_itemsarrayRequiredCart line containing add-ons.

Returns string: HTML list, or an empty string when there are no add-ons.

Note: This function name has no rpress_ prefix.

Internal. Defined in includes/cart/template.php, line 161.

rpress_empty_cart_message()#

Returns the empty cart message markup.

Returns a span with the text 'Choose an item from the menu to get started.', filtered by rpress_empty_cart_message.

rpress_empty_cart_message()

Returns string: HTML message.

Defined in includes/cart/template.php, line 211.

rpress_empty_checkout_cart()#

Echoes the empty cart message.

Hooked to rpress_cart_empty. Prints rpress_empty_cart_message() through wp_kses limited to span elements.

rpress_empty_checkout_cart()

Note: Echoes output instead of returning it.

Internal. Defined in includes/cart/template.php, line 221.

rpress_checkout_cart_columns()#

Returns the number of columns in the checkout cart table.

Starts from 3 and adds the number of callbacks attached to rpress_checkout_table_header_first and rpress_checkout_table_header_last. Applies the rpress_checkout_cart_columns filter.

rpress_checkout_cart_columns()

Returns int: Column count.

Internal. Defined in includes/cart/template.php, line 238.

rpress_save_cart_button()#

Outputs the Save Cart button, and a Restore Previous Cart button when one is saved.

Prints nothing if cart saving is disabled. Added to rpress_cart_footer_buttons by rpress_checkout_cart().

rpress_save_cart_button()

Note: Echoes output instead of returning it.

Internal. Defined in includes/cart/template.php, line 266.

Outputs a restore link on the empty cart message when a saved cart exists.

Hooked to rpress_cart_empty. Prints nothing if cart saving is disabled or no saved cart exists.

rpress_empty_cart_restore_cart_link()

Note: Echoes output instead of returning it.

Internal. Defined in includes/cart/template.php, line 289.

rpress_update_cart_button()#

Outputs the Update Cart submit button.

Prints a submit input and a hidden rpress_action=update_cart field when item quantities are enabled. Added to rpress_cart_footer_buttons by rpress_checkout_cart().

rpress_update_cart_button()

Note: Echoes output instead of returning it.

Internal. Defined in includes/cart/template.php, line 304.

rpress_display_cart_messages()#

Outputs and clears the cart messages stored in the session.

Hooked to rpress_before_checkout_cart. Prints each message in rpress_cart_messages in an alert div (class based on whether the text contains 'error' or 'success'), then clears the session value.

rpress_display_cart_messages()

Note: Echoes output instead of returning it.

Internal. Defined in includes/cart/template.php, line 319.

rpress_add_checkout_cart_form_start()#

Opens the checkout cart form element.

Hooked to rpress_before_checkout_cart. Prints the opening form tag with id rpress_checkout_cart_form.

rpress_add_checkout_cart_form_start()

Note: Echoes output instead of returning it.

Internal. Defined in includes/cart/template.php, line 372.

rpress_add_checkout_cart_form_end()#

Closes the checkout cart form element.

Hooked to rpress_after_checkout_cart. Prints the closing form tag.

rpress_add_checkout_cart_form_end()

Note: Echoes output instead of returning it.

Internal. Defined in includes/cart/template.php, line 384.

rpress_checkout_service_options_delivery_steps()#

Outputs the service options wrapper and fires the delivery steps action.

Hooked to rpress_checkout_service_options. Prints a div with class rp-checkout-service-option and fires rpress_get_delivery_steps inside it.

rpress_checkout_service_options_delivery_steps()

Note: Echoes output instead of returning it.

Internal. Defined in includes/cart/template.php, line 396.

rpress_show_added_to_cart_messages()#

Outputs an 'added to your cart' notice after a menu item is added by form post.

Hooked to rpress_after_fooditem_content. Prints the notice only when the request is a POST with rpress_action=add_to_cart, using the posted fooditem_id. The markup is filtered by rpress_show_added_to_cart_messages.

rpress_show_added_to_cart_messages($fooditem_id)

Parameters

ParameterTypeDefaultDescription
$fooditem_idintRequiredMenu item (fooditem) post ID; replaced by the posted fooditem_id if different.

Note: Echoes output instead of returning it.

Internal. Defined in includes/cart/template.php, line 410.

Was this page helpful?