Documentation · Frontend Guide
Favorites
This document covers the favorites (wishlist) feature of the ADP Car Market Hub WordPress Plugin: how visitors save vehicles, how the favorites page works, what data is shown, and what limitations apply.
When to use this document
Read this document if you are setting up the favorites feature for the first time, configuring which vehicle details appear on the favorites page, or helping a visitor understand how to save and revisit vehicles.
Overview
The favorites feature allows visitors to save vehicles they are interested in and view them later on a dedicated favorites page. Saved vehicle IDs are stored in the browser's localStorage. No account or login is required.
When a visitor opens the favorites page, the plugin retrieves the current vehicle data for all saved IDs from a REST API endpoint and renders the list dynamically. This means the favorites page always reflects the current state of the vehicle listing, including any price changes or vehicles that have been removed since they were saved.
Requirements or prerequisites
- The favorites feature must be enabled in the plugin settings (it is enabled by default).
- A favorites page must exist in WordPress with the
[as24ci_favorites]shortcode in its content. - The WordPress REST API must be publicly accessible for the favorites page to load vehicle data.
Step-by-step instructions
Set up the favorites page
- In the WordPress admin, go to Pages → Add New.
- Give the page a title such as "My Favorites" or "Saved Vehicles".
- In the page content, add the shortcode
[as24ci_favorites]. - Publish the page.
The favorites page renders a container that is populated by JavaScript on page load. No additional configuration of the shortcode is required.
Save a vehicle as a visitor
- On the vehicle archive, locate a vehicle card. A favorites button (heart icon) appears on the card when the favorites feature and the
favorite_btnelement are both enabled. - Click the heart button to add the vehicle to your favorites. The button changes state to indicate the vehicle is saved.
- Click the button again to remove the vehicle from your favorites.
The same favorites button is available on individual vehicle detail pages in the sticky floating action bar.
View saved favorites
- Navigate to the favorites page.
- The page loads and calls the plugin's REST endpoint to retrieve current data for all saved vehicle IDs.
- Each saved vehicle is displayed as a card with its image, title, price, and configured specification fields.
- Click "More details" on a card to open the vehicle's full detail page.
If no vehicles are saved, the page displays "You have no saved favorites yet."
Configuration reference
Favorites settings
| Setting | Location | Description |
|---|---|---|
| Enable favorites | Plugin settings → Settings (or Setup Wizard) | Enables or disables the entire favorites feature |
| Favorites fields | Layout Manager → Favorites | Which vehicle fields are shown on each favorites card |
Favorites page fields
Which vehicle fields are shown on each favorites card is controlled by the Layout Manager → Favorites zone. The following fields are supported and can be individually enabled or disabled:
| Field ID | Description |
|---|---|
price | Selling price (formatted with currency) |
mileage | Mileage in km |
firstRegistrationYear | Registration year |
fuelType | Fuel type |
transmissionType | Transmission |
bodyType | Body type |
conditionType | Condition (new or used) |
horsePower | Power in HP |
bodyColorText | Exterior color |
doors | Number of doors |
seats | Number of seats |
driveType | Drive type |
co2Emission | CO₂ emissions in g/km |
consumptionCombined | Combined fuel consumption in l/100 km |
energyLabel | Energy label |
firstRegistrationDate | First registration date (formatted) |
warrantyType | Warranty type |
Fields with no value for a vehicle, or numeric fields with a value of zero, are omitted from that vehicle's card. The order of fields follows the zone configuration.
Archive card favorites button
The favorites button appears on vehicle archive cards when:
- The favorites feature is enabled in the plugin settings (
FEATURE_FAVORITES). - The
favorite_btnelement is enabled in the Layout Manager → Archive Cards zone.
The button displays a heart icon and toggles the saved state when clicked.
Operational notes
- Vehicle IDs are stored in browser
localStorage. Favorites persist across page navigation and survive page reloads within the same browser. Clearing browser data (cookies and local storage) removes all saved favorites. - Favorites are not shared across devices or browsers. There is no server-side account storage for favorites.
- The favorites page fetches vehicle data from the REST endpoint
POST /wp-json/as24ci/v1/favoriteson each page load. The request body contains an array of post IDs. - The REST endpoint enforces a maximum of 50 vehicles per request. If more than 50 vehicles are stored in
localStorage, only the first 50 are retrieved. - Only published vehicles of the correct post type are returned by the REST endpoint. Vehicles that have been unpublished or deleted since they were saved are silently excluded from the response.
- The registration year is resolved using a priority chain: first from the mapped meta key for
firstRegistrationYear, then from the legacy_as24ci_yearmeta key, and finally from the Vehicle Field Resolver which checks the custom table and raw data columns. - Dates (first registration date) are formatted using the WordPress site date format setting.
- Numeric fields such as power and fuel consumption are omitted if their value is zero or empty, so that the card does not show "0 HP" or "0.0 l/100 km".
- The favorites JavaScript asset is enqueued on vehicle archive pages, single vehicle pages, and pages containing the
[as24ci_favorites]or[as24ci_archive]shortcode. - The favorites CSS and any configured design inline styles are enqueued alongside the JavaScript.
Troubleshooting
The favorites button does not appear on vehicle cards.
- Verify the favorites feature is enabled in the plugin settings.
- Check the Layout Manager → Archive Cards zone and confirm
favorite_btnis enabled.
The favorites page shows "Loading favorites…" and does not update.
- Check that the WordPress REST API is accessible. Many security plugins or server configurations block REST API access to non-logged-in users.
- Open the browser's developer console and check for JavaScript errors or failed network requests.
- Confirm the page contains the
[as24ci_favorites]shortcode.
The favorites page shows "Could not load favorites."
- The REST request to
/wp-json/as24ci/v1/favoritesfailed or returned an error. Check that the REST API is functioning correctly. - Verify the site's permalink settings allow REST API URLs to be resolved.
Saved vehicles disappear after a browser restart.
localStoragepersists across browser restarts in all modern browsers. If favorites are disappearing, the browser may be configured to clear storage on close, or a privacy mode (incognito/private window) may be in use.
A vehicle that was saved is no longer shown on the favorites page.
- The vehicle may have been unpublished or deleted from the WordPress admin after it was saved. The REST endpoint only returns published vehicles.
The favorites page shows only a subset of saved vehicles.
- The REST endpoint returns a maximum of 50 vehicles. If more than 50 vehicles are saved in
localStorage, only the first 50 are retrieved.