
WooCommerce Real-Time Product Viewer Plugin
WooCommerce Real-Time Product Viewer Documentation
Overview
The WooCommerce Real-Time Product Viewer plugin shows the variety of customers presently viewing a particular product in real-time. It gives reside updates utilizing AJAX requests and shops view counts in a JSON file.
Features:
- Displays the variety of customers presently viewing a product on single product pages and product record (store) pages.
- Supports customized CSS settings for font shade, alignment, and font household.
- Provides shortcode assist for dynamically displaying the view rely.
- Includes an admin settings web page for managing the plugin configuration.
Installation Guide
Step 1: Download the Plugin
- Download or clone the plugin recordsdata into your WooCommerce website beneath the
/wp-content/plugins/
listing.
Step 2: Upload the Plugin
- Upload the
product-viewer
listing to the/wp-content/plugins/
listing through FTP or by utilizing the WordPress Admin’s plugin add function.
Step 3: Activate the Plugin
- Log in to your WordPress admin dashboard.
- Navigate to Plugins > Installed Plugins.
- Find WooCommerce Real-Time Product Viewer within the record and click on Activate.
Step 4: Configure the Plugin
- Go to Settings > Product Viewer Settings to regulate the show settings comparable to enabling/disabling the view rely on single product and store pages, and customizing the CSS properties.
Usage Instructions
Displaying View Counts on Product Pages
- The plugin robotically reveals the variety of customers presently viewing a product on the product particulars web page if enabled within the settings.
- For product loops (e.g., store pages), the view rely may also be displayed under every product in a compact format.
Shortcode:
To show the real-time view rely on a customized web page or template, use the next shortcode:
[rt_product_viewer id=<span class="hljs-string">"PRODUCT_ID"</span>]
If no id
attribute is supplied, the shortcode will try and detect the present product ID.
Custom Columns in WooCommerce Admin:
- The plugin provides a customized column labeled “Viewing” within the WooCommerce product record, displaying what number of customers are presently viewing every product.
Developer Guide
The plugin is designed with each ease of use and customization in thoughts. It makes use of commonplace WordPress hooks, AJAX requests, and JSON knowledge storage. Below are some vital elements for builders to notice:
JavaScript (rt-product-viewer.js)
- The JavaScript file initializes on web page load and makes an attempt to detect the product ID.
- It sends periodic AJAX requests each 5 seconds to replace the view rely displayed on the product web page.
- It additionally sends a
beforeunload
occasion when the consumer leaves the web page to replace the server that the consumer is not viewing the product.
Key Functions:
- replaceProductViewDepend: Sends AJAX requests to retrieve the present variety of viewers for the product.
- beforeunload: Detects when the consumer is leaving the web page and updates the view rely accordingly.
PHP (woocommerce-real-time-viewer.php)
- The plugin registers customized AJAX actions (
rt_update_product_view_count
andrt_leave_product_view
) to replace and handle the product view rely. - The product view counts are saved in a JSON file (
view_counts.json
) and up to date primarily based on consumer periods.
Important Functions:
- rt_update_product_view_count: Handles the AJAX request to replace the product view rely.
- rt_leave_product_view: Handles the AJAX request when a consumer leaves the product web page, lowering the view rely.
- display_product_view_count: Displays the view rely for a particular product.
- rt_product_viewer_shortcode: Provides a shortcode for displaying view counts in customized templates.
- rt_get_currently_viewing_count: Helper operate to fetch the present view rely from the JSON file.
Admin Settings:
- The plugin gives a settings web page beneath Settings > Product Viewer Settings the place directors can allow/disable the view rely show for single product pages or product loops, and customise the CSS.
Settings Options:
- Enable on Single Product Page: Enables/disables the view rely on particular person product pages.
- Enable on Product List (Shop) Pages: Enables/disables the view rely on product archive pages.
- CSS Settings: Customize textual content alignment, font shade, and font household for each single product and product loop views.
CSS Customization:
Developers can simply modify the CSS for displaying the view rely utilizing the choices out there within the settings panel or by overriding types immediately within the theme.
JSON File (view_counts.json
)
- The JSON file shops real-time view knowledge with every product’s session data.
- Each product’s view rely is tied to a session, guaranteeing that every consumer is counted solely as soon as throughout their session.
FAQ
1. How usually is the view rely up to date?
The view rely is up to date each 5 seconds through an AJAX request.
2. Where is the view rely knowledge saved?
The view counts are saved in a view_counts.json
file positioned within the plugin listing.
3. Can I customise the textual content or look of the view rely show?
Yes, you may customise the textual content alignment, font shade, and font household from the settings web page beneath Product Viewer Settings.
4. Is the plugin suitable with caching plugins?
The plugin could not work as anticipated with aggressive caching. Ensure that your caching plugin excludes the product view rely function or AJAX calls from being cached.
Changelog
- Version 1.0
- Initial launch with real-time view rely performance for WooCommerce merchandise.
- AJAX-based updates to the view rely.
- Custom columns in WooCommerce product record.
- Shortcode assist for dynamic view rely show.