Function
Checkout upsell functions
On this page
- rpress_checkout_upsell_settings()
- rpress_checkout_upsell_sanitize_items()
- rpress_checkout_upsell_cart_ids()
- rpress_checkout_upsell_item_is_offerable()
- rpress_checkout_upsell_category_items()
- rpress_checkout_upsell_candidate_ids()
- rpress_checkout_upsell_needs_popup()
- rpress_checkout_upsell_display_amount()
- rpress_checkout_upsell_price()
- rpress_checkout_upsell_is_active()
- rpress_checkout_upsell_render()
- rpress_checkout_upsell_enqueue()
- rpress_checkout_upsell_register_settings()
- rpress_checkout_upsell_is_settings_screen()
- rpress_checkout_upsell_items_marker()
- rpress_checkout_upsell_fooditem_options()
- rpress_checkout_upsell_category_options()
- rpress_checkout_upsell_sanitize_setting()
Functions for the "Add to your order" upsell row at checkout.
18 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_upsell_settings()#
Returns the checkout upsell settings in normalized form.
Reads checkout_upsell_enable, checkout_upsell_heading, checkout_upsell_source, checkout_upsell_items and checkout_upsell_category unless raw values are passed. An empty heading becomes Add to your order and the source is items or category. Filterable through rpress_checkout_upsell_settings.
rpress_checkout_upsell_settings( $raw = null )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$raw | array|null | null | Optional raw option values (for tests); defaults to the saved settings. |
Returns array: Array with enabled (bool), heading, source (items or category), items (int[]) and category (int).
Example
$settings = rpress_checkout_upsell_settings();
if ( $settings['enabled'] ) {
$ids = $settings['items'];
}
Defined in includes/features/checkout-upsell/loader.php, line 35.
rpress_checkout_upsell_sanitize_items()#
Cleans a list of picked menu item IDs.
Accepts an array or a comma separated string. Keeps positive unique integers in order, up to the RPRESS_CHECKOUT_UPSELL_MAX limit of 4.
rpress_checkout_upsell_sanitize_items( $items )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$items | mixed | Required | Array or comma separated string of IDs. |
Returns int[]: The cleaned IDs.
Internal. Defined in includes/features/checkout-upsell/loader.php, line 74.
rpress_checkout_upsell_cart_ids()#
Returns the menu item IDs currently in the cart.
Reads rpress_get_cart_contents() and returns each item ID once.
rpress_checkout_upsell_cart_ids()
Returns int[]: Unique menu item IDs.
Example
$in_cart = rpress_checkout_upsell_cart_ids();
Defined in includes/features/checkout-upsell/loader.php, line 97.
rpress_checkout_upsell_item_is_offerable()#
Checks whether a menu item can be offered in the upsell row.
The item must be a published fooditem post and, when rpress_fooditem_available() exists, available.
rpress_checkout_upsell_item_is_offerable( $fooditem_id )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$fooditem_id | int | Required | Menu item ID. |
Returns bool: True when the item can be offered.
Internal. Defined in includes/features/checkout-upsell/loader.php, line 115.
rpress_checkout_upsell_category_items()#
Returns the published menu items of a category, best sellers first.
Fetches up to 50 items in menu order, then sorts by the _rpress_fooditem_sales meta, keeping menu order for ties.
rpress_checkout_upsell_category_items( $term_id )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$term_id | int | Required | food-category term ID. |
Returns int[]: Menu item IDs, or an empty array when the term ID is 0.
Internal. Defined in includes/features/checkout-upsell/loader.php, line 134.
rpress_checkout_upsell_candidate_ids()#
Returns the menu item IDs to show in the upsell row.
Takes items from the chosen source, skips items already in the cart and items that are not offerable, and keeps at most 4. Filterable through rpress_checkout_upsell_items.
rpress_checkout_upsell_candidate_ids( $settings = null, $cart_ids = null )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$settings | array|null | null | Normalized settings; defaults to rpress_checkout_upsell_settings(). |
$cart_ids | int[]|null | null | Menu item IDs in the cart; defaults to the live cart. |
Returns int[]: Up to 4 menu item IDs.
Example
$ids = rpress_checkout_upsell_candidate_ids();
Defined in includes/features/checkout-upsell/loader.php, line 197.
rpress_checkout_upsell_needs_popup()#
Checks whether adding the item needs the item popup instead of a direct add.
True for items with variable prices, a required add-on group, a minimum number of add-ons above zero, or pre-selected default add-ons. Filterable through rpress_checkout_upsell_needs_popup.
rpress_checkout_upsell_needs_popup( $fooditem_id )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$fooditem_id | int | Required | Menu item ID. |
Returns bool: True when the popup is needed.
Internal. Defined in includes/features/checkout-upsell/loader.php, line 239.
rpress_checkout_upsell_display_amount()#
Converts a price to the amount the menu displays, following the tax display settings.
Applies the prices_include_tax and tax_item settings at the item's tax rate. Filterable through rpress_checkout_upsell_display_amount.
rpress_checkout_upsell_display_amount( $fooditem_id, $amount )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$fooditem_id | int | Required | Menu item ID. |
$amount | float | Required | Price as entered on the item. |
Returns float: The display amount.
Internal. Defined in includes/features/checkout-upsell/loader.php, line 270.
rpress_checkout_upsell_price()#
Returns the price amount and display label for an upsell card.
Variable-price items show From and the lowest option; items with a zero price show Free.
rpress_checkout_upsell_price( $fooditem_id )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$fooditem_id | int | Required | Menu item ID. |
Returns array: Array with amount (the item's own price) and label (display text).
Internal. Defined in includes/features/checkout-upsell/loader.php, line 291.
rpress_checkout_upsell_is_active()#
Checks whether the upsell row should render on this request.
Requires the upsell to be enabled and AJAX not disabled. Filterable through rpress_checkout_upsell_is_active.
rpress_checkout_upsell_is_active()
Returns bool: True when the row renders.
Example
if ( rpress_checkout_upsell_is_active() ) {
// The checkout shows the upsell row.
}
Defined in includes/features/checkout-upsell/loader.php, line 312.
rpress_checkout_upsell_render()#
Prints the Add to your order row on the checkout page.
Hooked to rpress_payment_mode_select at priority 5, just before the Payment card. Prints nothing when inactive or when there are no candidate items.
rpress_checkout_upsell_render()
Note: Echoes output instead of returning it.
Internal. Defined in includes/features/checkout-upsell/loader.php, line 324.
rpress_checkout_upsell_enqueue()#
Enqueues the upsell row stylesheet and script on the checkout page.
Passes the AJAX URL, an add-to-cart nonce and messages to the script as rpress_checkout_upsell.
rpress_checkout_upsell_enqueue()
Internal. Defined in includes/features/checkout-upsell/loader.php, line 386.
rpress_checkout_upsell_register_settings()#
Registers the upsell fields in the General settings Checkout section.
Hooked to rpress_registered_settings. Adds the enable checkbox, heading, source, item picker and category fields. The item and category option lists are only built on the settings screen.
rpress_checkout_upsell_register_settings( $settings )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$settings | array | Required | Registered settings. |
Returns array: The settings with the upsell fields added.
Internal. Defined in includes/features/checkout-upsell/loader.php, line 419.
rpress_checkout_upsell_is_settings_screen()#
Checks whether this request draws the RestroPress settings page.
True in the admin, outside AJAX, when the page argument is rpress-settings. Filterable through rpress_checkout_upsell_build_setting_options.
rpress_checkout_upsell_is_settings_screen()
Returns bool: True on the settings screen.
Internal. Defined in includes/features/checkout-upsell/loader.php, line 499.
rpress_checkout_upsell_items_marker()#
Prints a hidden empty input for the upsell item picker.
Posts an empty value before the multi-select so clearing every pick saves an empty list.
rpress_checkout_upsell_items_marker()
Note: Echoes output instead of returning it.
Internal. Defined in includes/features/checkout-upsell/loader.php, line 511.
rpress_checkout_upsell_fooditem_options()#
Returns the menu item options for the settings select.
Lists up to 500 published fooditem posts ordered by title. The result is cached for the request.
rpress_checkout_upsell_fooditem_options()
Returns array: Menu item ID => title.
Internal. Defined in includes/features/checkout-upsell/loader.php, line 522.
rpress_checkout_upsell_category_options()#
Returns the category options for the settings select.
Lists all food-category terms, including empty ones, after a Choose a category placeholder. The result is cached for the request.
rpress_checkout_upsell_category_options()
Returns array: Term ID => name, with an empty-key placeholder.
Internal. Defined in includes/features/checkout-upsell/loader.php, line 550.
rpress_checkout_upsell_sanitize_setting()#
Sanitizes the upsell settings when settings are saved.
Hooked to rpress_settings_sanitize. Handles checkout_upsell_items, checkout_upsell_category, checkout_upsell_source and checkout_upsell_heading; other keys pass through.
rpress_checkout_upsell_sanitize_setting( $value, $key = '' )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$value | mixed | Required | Value. |
$key | string | '' | Setting key. |
Returns mixed: The sanitized value.
Internal. Defined in includes/features/checkout-upsell/loader.php, line 579.
