This guide presents a collection of helpful tips and tricks to help you manage resources that generate recommendations and guarantee smooth operations during high demand.
Just getting started with Product Recommendations? Read our Store Owner’s Guide to familiarize yourself with the basic concepts of the extension.
Woo Product Recommendations generates product recommendations on demand, in the background to conserve server resources and ensure proper functionality in all hosting environments. After creating and deploying a recommendation engine for the first time, it may be necessary to refresh the page a few times or wait a couple of minutes before you see the generated results.Â
The first user to view recommendations block every 24 hours triggers their (re)generation. If a page with recommendations does not receive any visit for 24 hours, the first user to visit it will see an older/expired version, which will trigger the regeneration process.
Depending on the store’s setup needs and load, further optimizations may be needed to improve performance in how recommendations are generated.
Extension Settings
↑ Back to top1. Adjust the “Cache Regeneration Period”
↑ Back to topThis period is set to 24 hours by default. You may adjust this based on the store’s needs to ensure that recommendations are always up-to-date, while maintaining a performant system.
2. Disable AJAX Rendering
↑ Back to topAJAX rendering is necessary for features like visibility conditions to work when any form of caching is used. If you don’t use caching in your store, you could consider turning off AJAX rendering to improve performance, as recommendations are created more efficiently and reduce the load on your server.
Engines and Amplifiers
↑ Back to topAmplifiers can be added to engines to adjust the display order of the filtered recommendations. Multiple weighted amplifiers can be added to perform advanced sorting operations.Â
As each amplifier represents an isolated query, every time recommendations try to generate results from an engine using multiple amplifiers, it needs to:
- Read the filters.
- Set up the filters and run a query for every amplifier.
- Merge the product lists into a single weighted list.
Therefore, it’s recommended not to overuse these amplifiers unless there is a specific need. One or two amplifiers often produce great results without overcomplicating and overloading resources.
For example, the engine on the left is almost 3 times faster than the one on the right.
Queue Management
↑ Back to topMonitor the Regeneration Queue
↑ Back to topMonitor the regeneration queue regularly to ensure timely recommendation processing. Navigate to WooCommerce > Status > Recommendations Queue to view the queue’s status, including pending and failed (re)generation tasks.
Throttling Requests from Being Queued
↑ Back to topStores with an extensive catalog may encounter performance issues, mainly when operating from an empty database. To mitigate this, you can employ throttling mechanisms, where a transient is used to “lock” the queuing process for a specified period to reduce bloat.
The system defaults to a 1-minute throttle. To set it to a longer duration, like 2 minutes, use the following code snippet:
add_filter(
'wc_prl_generation_task_throttle',
function() {
return 2 * MINUTE_IN_SECONDS;
}
);
Note: Throttling can be added or removed anytime (Return 0 to remove.) This feature is useful when you want to spread the workload over time. However, using throttling for a long time could lead to significant delays in generating recommendations. It’s always a trade-off between efficient performance and delay.
Generating Recommendations
↑ Back to top(Re)generation Requests
↑ Back to topEach queue item is handled here using a 1-minute Action Scheduler (AS) recurring task. This task will continue generating recommendations until it is complete or until time or memory limits are reached.
Running Regeneration Requests via WP-CLI
↑ Back to topIn most situations, the extension’s on-demand recommendation generation is adequate. However, if you need more control, especially during times of low server load, you have the option to use the WP-CLI command to dispatch queued (re)generation tasks manually. This can also be a good choice if you prefer to handle recommendations solely via WP-CLI without running AS through it. First, use the following snippet to prevent the extension from dispatching on-demand (re)generation tasks:
add_filter( 'woocommerce_prl_queue_via_wp_cli', '__return_true' );
Run the following command to dispatch queued tasks manually:
wp wc prl process-generation-queue
Command options
- –max-iterations: (int) Control the number of iterations to process within the queue. Useful to control the workload in batches. Default 0 (no limit.)
Details
- The extension will process the queue until empty unless the
--max-iterations
option is set to a specific number. - Completing a single recommendation list may take anywhere from 2 to 8 iterations.
- Use a native cron job during times of low server load running, e.g.,
wp wc prl process-generation-queue --max-iterations=1000
Note: Enabling WP-CLI at the extension level means that generations will only occur using the custom command. Even if Action Scheduler runs via WP-CLI, you’d still need to run this command separately.
Running Action Scheduler via WP-CLI
↑ Back to topWoo’s Action Scheduler (AS) has a feature that lets a store shift the handling of all AS actions to WP-CLI commands. This feature provides custom WP-CLI commands for processing actions, making it a better option for running action queues on larger sites than the default AS runner. When running AS jobs using WP-CLI, async requests are not triggered, as everything runs within the same request.
To switch AS to WP-CLI, use the following snippet:
add_action( 'init', function () {
if ( class_exists( 'ActionScheduler' ) ) {
remove_action( 'action_scheduler_run_queue', array( ActionScheduler::runner(), 'run' ) );
}
} );
Check out more details and usage here: https://actionscheduler.org/wp-cli/
Caution: Using the filter will prevent wp-cron from running actions associated with the AS. Use this with caution if you already have a setup to handle those, like running the wp action-scheduler run
command using e.g. unix cron jobs.
Note: All regeneration requests are stored under the group wc_prl_generator
. This allows them to run any time using the wp action-scheduler run --group=wc_prl_generator command
.
Tracking and Cookies
↑ Back to topProduct Recommendations also include an analytics dashboard for measuring conversion rates. A cookie is used to achieve that in a performance-oriented way.
Note: All cookies in the plugin are set using JavaScript by adding them directly using document.cookie = … without the need to run setcookie
in PHP. This ensures more consistent tracking data when an HTML cache is used.
The Click-to-Purchase Conversion Tracking Cookie
↑ Back to topThe process is as follows:
- If a shopper clicks on a recommended product, a cookie named wc_prl_deployments_clicked is getting created/updated.
- Once a product is added to the cart, the system reads from that cookie, and if the product has been clicked in the current session*, a new conversion event is recorded. (See WooCommerce > Settings > Recommendations > Tracking Session)
To disable tracking features, and thus the handling of the cookie, use the following snippet:
add_filter( 'woocommerce_prl_tracking_enabled', '__return_false' );
Note: Disabling tracking features will also remove the “Performance” page in the admin area.
The Recently Viewed Products Cookie
↑ Back to topThis cookie is used by the extension to generate “Recently Viewed Products” lists. It’s called wc_prl_recently_viewed
.
Note: This cookie is essential for the “Recently Viewed Products” filters to function properly and cannot be disabled.
Known Caveats
↑ Back to topWhile these optimizations enhance performance, be aware of the following caveats:
- Out-of-Stock Products: If the regeneration period is not managed correctly or AJAX rendering is disabled, out-of-stock products might appear in recommendations depending on the external caching timeframe.
- Recently Viewed Products: These products stem from the recently viewed cookie value, and if your store has HTML caching, they should only work as expected in uncached pages like the Cart and Checkout pages.
- Visibility Conditions: When AJAX rendering is disabled, visibility conditions will not work, which might impact how recommendations are displayed to users.
- WP-CLI Handling: Managing regeneration requests via WP-CLI may affect the overall user experience. Changes within the recommendation engine configuration can only be tested by running the CLI command, which might not be as convenient as automated processes.