Function
Customer account functions
On this page
- rpress_account_hub_max_addresses()
- rpress_account_hub_sanitize_address()
- rpress_account_hub_get_addresses()
- rpress_account_hub_get_default_index()
- rpress_account_hub_address_fingerprint()
- rpress_account_hub_find_address()
- rpress_account_hub_store_addresses()
- rpress_account_hub_save_address()
- rpress_account_hub_set_default_address()
- rpress_account_hub_delete_address()
- rpress_account_hub_format_address()
- rpress_account_hub_handle_address_request()
- rpress_account_hub_ajax_delete_address()
- rpress_account_hub_ajax_default_address()
- rpress_account_hub_handle_dashboard_posts()
- rpress_account_hub_update_profile()
- rpress_account_hub_flag_address_on_insert()
- rpress_account_hub_address_save_statuses()
- rpress_account_hub_save_address_on_status()
- rpress_account_hub_save_address_from_payment()
- rpress_account_hub_reorder_setting_copy()
- rpress_account_hub_show_reorder_notice()
- rpress_account_hub_reorder_notice()
- rpress_account_hub_handle_reorder_notice()
- rpress_account_hub_order_receipt_url()
- rpress_account_hub_order_is_live()
- rpress_account_hub_tracking_link()
- rpress_account_hub_dashboard_order_actions()
- rpress_account_hub_form_nonce()
- rpress_account_hub_dashboard_notice()
- rpress_account_hub_checkout_address_picker()
- rpress_account_hub_checkout_save_option()
- rpress_account_hub_page_type()
- rpress_account_hub_enqueue_assets()
- rpress_account_hub_reorder_enabled()
- rpress_account_hub_can_access_order()
- rpress_account_hub_reorder_line_problem()
- rpress_account_hub_line_price_id()
- rpress_account_hub_line_name()
- rpress_account_hub_reorder()
- rpress_account_hub_reorder_modal_html()
- rpress_account_hub_ajax_reorder()
Functions behind the customer account dashboard: saved delivery addresses, order tracking, reorder and the reservations tab.
42 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_account_hub_max_addresses()#
Returns the maximum number of saved addresses one customer can keep.
Default is 20. Filter with rpress_account_hub_max_addresses.
rpress_account_hub_max_addresses()
Returns int: Maximum address count.
Defined in includes/features/account-hub/addresses.php, line 30.
rpress_account_hub_sanitize_address()#
Normalizes and sanitizes one address array into the address book format.
Accepts the stored keys plus the checkout and order keys flat, postcode and label, which map to apt_suite, pincode and address_type. Returns the keys first_name, last_name, phone, address, apt_suite, city, pincode, address_type and default_address. A blank label becomes Home; labels are cut to 40 characters.
rpress_account_hub_sanitize_address( $data )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$data | array | Required | Raw address data. |
Returns array: Sanitized address with default_address set to 0 or 1.
Example
$address = rpress_account_hub_sanitize_address( array(
'address' => '12 High Street',
'city' => 'Leeds',
'postcode' => 'LS1 4AB',
'label' => 'Work',
) );
Defined in includes/features/account-hub/addresses.php, line 41.
rpress_account_hub_get_addresses()#
Returns a customer's saved addresses keyed by index, each with an is_default flag.
Reads the user_addresses user meta and sanitizes each entry. Returns an empty array for a missing user or when nothing is saved.
rpress_account_hub_get_addresses( $user_id )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$user_id | int | Required | WordPress user ID. |
Returns array: Addresses keyed by integer index; each is a sanitized address plus a boolean is_default.
Example
foreach ( rpress_account_hub_get_addresses( get_current_user_id() ) as $index => $address ) {
echo esc_html( rpress_account_hub_format_address( $address ) );
}
Defined in includes/features/account-hub/addresses.php, line 73.
rpress_account_hub_get_default_index()#
Returns the index of a customer's default address, or null when there is none.
Returns null when the stored default index is missing or does not point at an existing address.
rpress_account_hub_get_default_index( $user_id )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$user_id | int | Required | WordPress user ID. |
Returns int|null: Default address index, or null.
Defined in includes/features/account-hub/addresses.php, line 101.
rpress_account_hub_address_fingerprint()#
Builds a normalized key used to detect the same address saved twice.
Joins the lower-cased, whitespace-collapsed address, apt_suite, city and pincode values with a pipe.
rpress_account_hub_address_fingerprint( $address )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$address | array | Required | Sanitized address. |
Returns string: Fingerprint string.
Internal. Defined in includes/features/account-hub/addresses.php, line 116.
rpress_account_hub_find_address()#
Finds the saved address that matches the given address data.
Compares fingerprints (street, apt_suite, city, pincode), so the label and contact details are ignored.
rpress_account_hub_find_address( $user_id, $data )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$user_id | int | Required | WordPress user ID. |
$data | array | Required | Address data; sanitized before comparing. |
Returns int|null: Index of the matching address, or null.
Defined in includes/features/account-hub/addresses.php, line 132.
rpress_account_hub_store_addresses()#
Writes the address book to user meta, dropping the computed is_default flag.
Overwrites the user_addresses user meta. Does not touch the default index.
rpress_account_hub_store_addresses( $user_id, $addresses )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$user_id | int | Required | WordPress user ID. |
$addresses | array | Required | Addresses keyed by index. |
Internal. Defined in includes/features/account-hub/addresses.php, line 149.
rpress_account_hub_save_address()#
Adds a new saved address or updates an existing one for a customer.
Needs a street address and a city. With no index, an address that already matches a saved one refreshes that entry instead of duplicating it; otherwise a new index is used, up to the maximum. The first address, an address flagged default_address, or an edit of the current default becomes the default. Fires rpress_account_hub_address_saved.
rpress_account_hub_save_address( $user_id, $data, $index = null )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$user_id | int | Required | WordPress user ID. |
$data | array | Required | Address data: address, city, pincode or postcode, optional apt_suite, address_type or label, first_name, last_name, phone, default_address. |
$index | int|null | null | Index to update, or null to add. |
Returns int|WP_Error: Index of the saved address, or a WP_Error with code rpress_address_user, rpress_address_incomplete, rpress_address_limit or rpress_address_missing.
Example
$index = rpress_account_hub_save_address( get_current_user_id(), array(
'address' => '12 High Street',
'city' => 'Leeds',
'pincode' => 'LS1 4AB',
'address_type' => 'Home',
'default_address' => 1,
) );
if ( is_wp_error( $index ) ) {
error_log( $index->get_error_message() );
}
Note: Low level: performs no permission check. When an update omits first_name, last_name or phone, the stored values are kept.
Defined in includes/features/account-hub/addresses.php, line 169.
rpress_account_hub_set_default_address()#
Makes a saved address the customer's default and the one checkout prefills.
Updates the user_default_address_index and _rpress_user_delivery_address user meta. Copies first name, last name and phone to the user (first_name, last_name, _rpress_phone) when the address has them.
rpress_account_hub_set_default_address( $user_id, $index )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$user_id | int | Required | WordPress user ID. |
$index | int | Required | Address index in the customer's address book. |
Returns bool: True on success, false when the index does not exist.
Defined in includes/features/account-hub/addresses.php, line 225.
rpress_account_hub_delete_address()#
Deletes a saved address, promoting the first remaining one when it was the default.
Fires rpress_account_hub_address_deleted after a successful delete.
rpress_account_hub_delete_address( $user_id, $index )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$user_id | int | Required | WordPress user ID. |
$index | int | Required | Address index in the customer's address book. |
Returns bool: True when deleted, false when the index does not exist.
Defined in includes/features/account-hub/addresses.php, line 270.
rpress_account_hub_format_address()#
Formats an address as a one-line summary for lists and selects.
Joins the street with apt_suite, and the city with pincode, using commas. The array must contain the address, apt_suite, city and pincode keys, as returned by the sanitizer.
rpress_account_hub_format_address( $address )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$address | array | Required | Sanitized address. |
Returns string: Plain text summary.
Defined in includes/features/account-hub/addresses.php, line 298.
rpress_account_hub_handle_address_request()#
Runs a save, delete or set-default address action for the current user.
Always acts on the logged-in user; there is no user ID parameter. The request may carry an index key to target an address.
rpress_account_hub_handle_address_request( $action, $request )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$action | string | Required | One of save, delete or set_default. |
$request | array | Required | Request data, already unslashed. |
Returns int|true|WP_Error: Saved index for save, true for delete and set_default, or a WP_Error (rpress_address_login, rpress_address_missing, rpress_address_action, or an error from the save).
Internal. Defined in includes/features/account-hub/addresses.php, line 311.
rpress_account_hub_ajax_delete_address()#
Handles the dashboard AJAX request that deletes a saved address.
Hooked at priority 5 to wp_ajax_rpress_delete_user_address, ahead of the core handler. Verifies the rpress-user-address nonce (field security) and sends a JSON success flag.
rpress_account_hub_ajax_delete_address()
Internal. Defined in includes/features/account-hub/addresses.php, line 340.
rpress_account_hub_ajax_default_address()#
Handles the dashboard AJAX request that sets the default address.
Hooked at priority 5 to wp_ajax_rpress_default_user_address, ahead of the core handler. Verifies the rpress-user-address nonce (field security) and sends a JSON success flag.
rpress_account_hub_ajax_default_address()
Internal. Defined in includes/features/account-hub/addresses.php, line 347.
rpress_account_hub_handle_dashboard_posts()#
Processes the customer dashboard address and profile forms before the page renders.
Runs on template_redirect. Requires a logged-in user and the rpress-account-hub nonce; otherwise the submit flags are removed from the request. On success it redirects back with an rpress_account notice code (post, redirect, get) and exits.
rpress_account_hub_handle_dashboard_posts()
Internal. Defined in includes/features/account-hub/addresses.php, line 359.
rpress_account_hub_update_profile()#
Updates the current customer's name, email and phone from the dashboard profile form.
Empty names are ignored. An email already used by another account is rejected. The phone is stored in the _rpress_phone user meta.
rpress_account_hub_update_profile( $user_id, $data )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$user_id | int | Required | User ID, always the current user. |
$data | array | Required | Unslashed form data with first_name, last_name, email and phone. |
Returns string: Notice code: profile_saved, email_in_use or profile_error.
Internal. Defined in includes/features/account-hub/addresses.php, line 399.
rpress_account_hub_flag_address_on_insert()#
Flags an order so its delivery address is saved when the customer asked at checkout.
Hooked to rpress_insert_payment. Applies only to a logged-in customer ordering for themselves with the delivery service and rpress_save_address posted. Stores the label in the _rpress_save_address order meta and saves immediately if the order already has a placed status.
rpress_account_hub_flag_address_on_insert( $payment_id, $payment_data )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$payment_id | int | Required | Payment ID. |
$payment_data | array | Required | Payment data, including user_info. |
Internal. Defined in includes/features/account-hub/addresses.php, line 439.
rpress_account_hub_address_save_statuses()#
Returns the order statuses that count as a placed order for saving an address.
Defaults to publish, complete and processing. Filter with rpress_account_hub_address_save_statuses.
rpress_account_hub_address_save_statuses()
Returns array: List of payment status slugs.
Internal. Defined in includes/features/account-hub/addresses.php, line 463.
rpress_account_hub_save_address_on_status()#
Saves the flagged address when an order moves to a placed status.
Hooked to rpress_update_payment_status.
rpress_account_hub_save_address_on_status( $payment_id, $new_status )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$payment_id | int | Required | Payment ID. |
$new_status | string | Required | New payment status. |
Internal. Defined in includes/features/account-hub/addresses.php, line 473.
rpress_account_hub_save_address_from_payment()#
Copies a flagged order's delivery address into the customer's address book.
Reads and removes the _rpress_save_address order meta, so it runs once per order. Uses the order's _rpress_delivery_address meta and the customer's stored phone. Returns false for guest orders or orders without a street address.
rpress_account_hub_save_address_from_payment( $payment_id )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$payment_id | int | Required | Payment ID. |
Returns int|false: Saved address index, or false.
Internal. Defined in includes/features/account-hub/addresses.php, line 487.
rpress_account_hub_reorder_setting_copy()#
Relabels the reorder setting as One-tap reorder with a clearer description.
Filter callback on rpress_registered_settings that rewrites the name and description of the rp_reorder field.
rpress_account_hub_reorder_setting_copy( $settings )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$settings | array | Required | Registered settings. |
Returns array: Modified settings.
Internal. Defined in includes/features/account-hub/admin.php, line 21.
rpress_account_hub_show_reorder_notice()#
Checks whether the reorder notice should show on the settings screen.
True when the user can manage_shop_settings, reorder is off and the notice was not dismissed.
rpress_account_hub_show_reorder_notice()
Returns bool: True when the notice is due.
Internal. Defined in includes/features/account-hub/admin.php, line 40.
rpress_account_hub_reorder_notice()#
Prints the admin notice offering to enable one-tap reorder.
Shows only on the rpress-settings page. Echoes output.
rpress_account_hub_reorder_notice()
Note: Echoes output instead of returning it.
Internal. Defined in includes/features/account-hub/admin.php, line 49.
rpress_account_hub_handle_reorder_notice()#
Enables reorder or dismisses its notice from the admin-post action.
Requires manage_shop_settings and the rpress-reorder-notice nonce. Either choice records the rpress_reorder_notice_dismissed option, then redirects to the settings page.
rpress_account_hub_handle_reorder_notice()
Internal. Defined in includes/features/account-hub/admin.php, line 79.
rpress_account_hub_order_receipt_url()#
Returns the receipt URL of an order, which shows the live order status.
Builds the success page URL with the order's payment_key. Filter with rpress_account_hub_order_receipt_url.
rpress_account_hub_order_receipt_url( $payment_id )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$payment_id | int | Required | Payment ID. |
Returns string: Receipt URL, or an empty string when the order has no key or no success page is set.
Defined in includes/features/account-hub/frontend.php, line 20.
rpress_account_hub_order_is_live()#
Checks whether an order is still in progress and worth tracking live.
False for failed, refunded, revoked and abandoned orders, and for orders whose status phase is delivered or cancelled.
rpress_account_hub_order_is_live( $payment_id )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$payment_id | int | Required | Payment ID. |
Returns bool: True while the order is in progress.
Defined in includes/features/account-hub/frontend.php, line 39.
rpress_account_hub_tracking_link()#
Prints a Track order or Receipt link for an order card.
Prints nothing when the order has no receipt URL. Hooked to rpress_order_after_view_details and rpress_order_details_modal_actions.
rpress_account_hub_tracking_link( $payment_id )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$payment_id | int | Required | Payment ID. |
Note: Echoes output instead of returning it.
Internal. Defined in includes/features/account-hub/frontend.php, line 54.
rpress_account_hub_dashboard_order_actions()#
Prints the tracking link and, when enabled, a Reorder button in the dashboard Orders tab.
Hooked to rpress_user_dashboard_order_actions.
rpress_account_hub_dashboard_order_actions( $payment_id )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$payment_id | int | Required | Payment ID. |
Note: Echoes output instead of returning it.
Internal. Defined in includes/features/account-hub/frontend.php, line 76.
rpress_account_hub_form_nonce()#
Prints the nonce field for the dashboard address and profile forms.
Outputs the rpress_account_hub_nonce field for the rpress-account-hub action.
rpress_account_hub_form_nonce()
Internal. Defined in includes/features/account-hub/frontend.php, line 91.
rpress_account_hub_dashboard_notice()#
Prints the result message shown after a dashboard form redirect.
Reads the rpress_account query argument and shows a message only for known codes.
rpress_account_hub_dashboard_notice()
Note: Echoes output instead of returning it.
Internal. Defined in includes/features/account-hub/frontend.php, line 100.
rpress_account_hub_checkout_address_picker()#
Prints the saved address dropdown above the delivery fields at checkout.
Shows only for logged-in customers with saved addresses and the delivery service. Preselects the address matching the prefilled fields, or the default when the fields are empty.
rpress_account_hub_checkout_address_picker()
Note: Echoes output instead of returning it.
Internal. Defined in includes/features/account-hub/frontend.php, line 128.
rpress_account_hub_checkout_save_option()#
Prints the Save this address checkbox and label selector at checkout.
Shows only for logged-in customers with the delivery service. Labels come from the rpress_account_hub_address_labels filter (Home, Work, Other by default). The checkbox is ticked when the customer has no saved address.
rpress_account_hub_checkout_save_option()
Note: Echoes output instead of returning it.
Internal. Defined in includes/features/account-hub/frontend.php, line 183.
rpress_account_hub_page_type()#
Returns whether the current page shows the customer dashboard or order history.
Detects the customer_dashboard shortcode, the order_history shortcode or the restropress/order-history block in a singular post.
rpress_account_hub_page_type()
Returns string: 'dashboard', 'history' or an empty string.
Internal. Defined in includes/features/account-hub/frontend.php, line 218.
rpress_account_hub_enqueue_assets()#
Enqueues the account hub styles and scripts only on checkout and account pages.
Hooked to wp_enqueue_scripts at priority 20. The script loads at checkout for logged-in users; rp-reorder is enqueued on the dashboard when reorder is on.
rpress_account_hub_enqueue_assets()
Internal. Defined in includes/features/account-hub/frontend.php, line 235.
rpress_account_hub_reorder_enabled()#
Checks whether one-tap reorder is switched on for the store.
Reads the rp_reorder setting.
rpress_account_hub_reorder_enabled()
Returns bool: True when reorder is enabled.
Defined in includes/features/account-hub/reorder.php, line 22.
rpress_account_hub_can_access_order()#
Checks whether the current visitor may act on an order.
Logged-in customers can access only their own orders. Guests can access only guest orders, and only when the matching payment key is supplied.
rpress_account_hub_can_access_order( $order_id, $payment_key = '' )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$order_id | int | Required | Payment ID. |
$payment_key | string | '' | Payment key sent by a guest. |
Returns bool: True when access is allowed.
Defined in includes/features/account-hub/reorder.php, line 34.
rpress_account_hub_reorder_line_problem()#
Returns why a past order line cannot be bought again, or an empty string when it can.
Checks that the menu item exists, can be purchased and is currently available, and that a variable price option still exists. Filter with rpress_account_hub_reorder_line_problem to add reasons.
rpress_account_hub_reorder_line_problem( $line )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$line | array | Required | Cart line from rpress_get_payment_meta_cart_details(). |
Returns string: 'missing', 'unavailable', 'option_gone', a filtered reason, or an empty string.
Internal. Defined in includes/features/account-hub/reorder.php, line 55.
rpress_account_hub_line_price_id()#
Returns the price option a past order line was ordered with.
Looks in item_number options, then item_number.
rpress_account_hub_line_price_id( $line )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$line | array | Required | Cart line. |
Returns int|null: Price ID, or null when the line had none.
Internal. Defined in includes/features/account-hub/reorder.php, line 80.
rpress_account_hub_line_name()#
Returns the display name of a past order line.
Falls back to the menu item title, then to the text An item.
rpress_account_hub_line_name( $line )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$line | array | Required | Cart line. |
Returns string: Line name.
Internal. Defined in includes/features/account-hub/reorder.php, line 96.
rpress_account_hub_reorder()#
Adds an order's items back to the cart at today's prices, skipping lines that cannot be bought.
Re-checks every line against the current menu. Add-ons whose add-on group term was removed are dropped from the line and the line is listed in changed. Result is filterable with rpress_account_hub_reorder_result.
rpress_account_hub_reorder( $order_id )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$order_id | int | Required | Payment ID. The caller must check access first. |
Returns array: Array with keys added, skipped, changed (line names) and keys (cart keys of the added lines).
Example
if ( rpress_account_hub_can_access_order( $order_id ) ) {
$result = rpress_account_hub_reorder( $order_id );
error_log( count( $result['added'] ) . ' lines added' );
}
Note: Adds to the current visitor's cart. Does not check who owns the order.
Defined in includes/features/account-hub/reorder.php, line 116.
rpress_account_hub_reorder_modal_html()#
Builds the modal HTML that reports what a reorder added and skipped.
Includes the skipped lines, lines that lost add-ons, and Add more items and Checkout Now links.
rpress_account_hub_reorder_modal_html( $order_id, $result )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$order_id | int | Required | Payment ID. |
$result | array | Required | Result of rpress_account_hub_reorder(). |
Returns string: Modal HTML.
Internal. Defined in includes/features/account-hub/reorder.php, line 193.
rpress_account_hub_ajax_reorder()#
Handles the reorder AJAX request.
Hooked at priority 5 on wp_ajax_rpress_reorder, wp_ajax_nopriv_rpress_reorder and rp_ajax_reorder. Verifies the show-order-details nonce, checks order access and returns the modal HTML, added and skipped names and the cart quantity as JSON.
rpress_account_hub_ajax_reorder()
Internal. Defined in includes/features/account-hub/reorder.php, line 259.
