WooCommerce Performance Optimization
Before writing code
Fetch live docs:
- Web-search
site:developer.woocommerce.com performance for performance guide
- Web-search
woocommerce hpos performance benefits for HPOS optimization details
- Web-search
wordpress object caching best practices for caching patterns
HPOS (High-Performance Order Storage)
Why It Matters
HPOS moves orders from wp_posts/wp_postmeta to dedicated tables:
- Dramatically faster order queries (custom indexes)
- Reduces
wp_posts table bloat
- Better database performance at scale
- Required for WooCommerce's future direction
Enabling HPOS
WooCommerce > Settings > Advanced > Features:
- Enable "Custom order tables"
- Run the migration tool to migrate existing orders
- Enable "Sync" during transition period
- Once verified, disable sync and use custom tables as authoritative
Compatibility Requirements
Extensions must:
- Use CRUD methods (
$order->get_meta(), $order->set_status(), $order->save())
- NOT use
get_post_meta() / update_post_meta() on orders
- NOT use
WP_Query with post_type => 'shop_order'
- Declare compatibility via
FeaturesUtil::declare_compatibility()
Object Caching
WordPress Object Cache
wp_cache_get() / wp_cache_set() — in-memory cache per request:
- With Redis/Memcached: persistent across requests
- Always use cache groups:
wp_cache_set( $key, $data, 'my_plugin' )
- Set appropriate expiration
- Use
wp_cache_delete() when data changes
Transients
set_transient() / get_transient() — cached values with expiration:
- Stored in DB without object cache, in-memory with object cache
- Use for: API responses, computed values, rate calculations
- Always handle cache miss (regenerate data when transient expires)
- Delete transients when underlying data changes
WooCommerce Cache Helpers
WC_Cache_Helper — manages WooCommerce-specific caching
wc_get_transient_version( 'product' ) — cache versioning for products
- Cache invalidation on product/order changes via version bumps
Database Optimization
Query Optimization
- Use
wc_get_orders() / wc_get_products() instead of WP_Query
- Limit queries: always use
limit/per_page parameters
- Avoid
meta_query on large tables — use HPOS custom columns instead
- Use
'fields' => 'ids' when you only need IDs
- Avoid
'no_found_rows' => false on large result sets
Index Optimization
- Ensure custom tables have proper indexes on queried columns
- WooCommerce HPOS tables include optimized indexes by default
- For custom tables: add indexes on columns used in WHERE, JOIN, ORDER BY
Background Processing
Move heavy operations out of the request cycle:
- Action Scheduler — WooCommerce's job queue
- Schedule:
as_schedule_single_action( $timestamp, 'hook_name', $args )
- Recurring:
as_schedule_recurring_action( $timestamp, $interval, 'hook_name', $args )
- Handles retries, failure logging, and concurrent execution
Frontend Performance
Asset Loading
- Conditionally load CSS/JS only on relevant pages
- Use
wp_enqueue_script with strategy => 'defer' or 'async'
- Combine/minify assets in production
- Use
wp_script_add_data( $handle, 'strategy', 'defer' )
Cart Fragments
AJAX cart fragment refreshing can be a bottleneck:
- Filter
woocommerce_cart_fragments to minimize data
- Disable on pages where cart widget isn't shown
- Use
wc_cart_fragments_params localized data
Image Optimization
- Use WordPress responsive images (
srcset, sizes)
- Enable lazy loading:
loading="lazy" on product images
- Use WebP format where supported
- Configure image sizes:
add_image_size() and WooCommerce image settings
Action Scheduler
Using Action Scheduler
WooCommerce's built-in background job processor:
as_schedule_single_action( time(), 'my_hook', $args, 'my-group' ) — run once
as_schedule_recurring_action( time(), HOUR_IN_SECONDS, 'my_hook', $args ) — recurring
as_enqueue_async_action( 'my_hook', $args ) — ASAP execution
as_unschedule_action( 'my_hook', $args ) — cancel
- Monitor via WooCommerce > Status > Scheduled Actions
When to Use
- Sending batch emails
- Syncing inventory with external systems
- Generating reports
- Processing large data imports/exports
- Cleaning up expired data
Best Practices
- Enable HPOS for new stores and migrate existing ones
- Use persistent object cache (Redis/Memcached) in production
- Cache expensive computations and API responses with transients
- Use Action Scheduler for background processing — never process heavy tasks during HTTP requests
- Profile with Query Monitor plugin to identify slow queries
- Conditionally load assets only on pages where needed
- Use
wc_get_orders() / wc_get_products() with appropriate limits
- Avoid N+1 query patterns — batch load related data
Fetch the WooCommerce performance documentation and HPOS migration guide for exact configuration, migration steps, and optimization techniques before implementing.
1---2name: woo-performance3description: Optimize WooCommerce performance — object caching, transients, HPOS, database optimization, Action Scheduler, lazy loading, and query optimization. Use when improving store performance or diagnosing slowness.4allowed-tools: Read, Write, Edit, Bash, Grep, Glob, WebSearch, WebFetch5metadata:6 source: https://skillmd.com/skills/orcaqubits/woo-performance7---89# WooCommerce Performance Optimization1011## Before writing code1213**Fetch live docs**:141. Web-search `site:developer.woocommerce.com performance` for performance guide152. Web-search `woocommerce hpos performance benefits` for HPOS optimization details163. Web-search `wordpress object caching best practices` for caching patterns1718## HPOS (High-Performance Order Storage)1920### Why It Matters2122HPOS moves orders from `wp_posts`/`wp_postmeta` to dedicated tables:23- Dramatically faster order queries (custom indexes)24- Reduces `wp_posts` table bloat25- Better database performance at scale26- Required for WooCommerce's future direction2728### Enabling HPOS2930WooCommerce > Settings > Advanced > Features:31- Enable "Custom order tables"32- Run the migration tool to migrate existing orders33- Enable "Sync" during transition period34- Once verified, disable sync and use custom tables as authoritative3536### Compatibility Requirements3738Extensions must:39- Use CRUD methods (`$order->get_meta()`, `$order->set_status()`, `$order->save()`)40- NOT use `get_post_meta()` / `update_post_meta()` on orders41- NOT use `WP_Query` with `post_type => 'shop_order'`42- Declare compatibility via `FeaturesUtil::declare_compatibility()`4344## Object Caching4546### WordPress Object Cache4748`wp_cache_get()` / `wp_cache_set()` — in-memory cache per request:49- With Redis/Memcached: persistent across requests50- Always use cache groups: `wp_cache_set( $key, $data, 'my_plugin' )`51- Set appropriate expiration52- Use `wp_cache_delete()` when data changes5354### Transients5556`set_transient()` / `get_transient()` — cached values with expiration:57- Stored in DB without object cache, in-memory with object cache58- Use for: API responses, computed values, rate calculations59- Always handle cache miss (regenerate data when transient expires)60- Delete transients when underlying data changes6162### WooCommerce Cache Helpers6364- `WC_Cache_Helper` — manages WooCommerce-specific caching65- `wc_get_transient_version( 'product' )` — cache versioning for products66- Cache invalidation on product/order changes via version bumps6768## Database Optimization6970### Query Optimization7172- Use `wc_get_orders()` / `wc_get_products()` instead of `WP_Query`73- Limit queries: always use `limit`/`per_page` parameters74- Avoid `meta_query` on large tables — use HPOS custom columns instead75- Use `'fields' => 'ids'` when you only need IDs76- Avoid `'no_found_rows' => false` on large result sets7778### Index Optimization7980- Ensure custom tables have proper indexes on queried columns81- WooCommerce HPOS tables include optimized indexes by default82- For custom tables: add indexes on columns used in WHERE, JOIN, ORDER BY8384### Background Processing8586Move heavy operations out of the request cycle:87- **Action Scheduler** — WooCommerce's job queue88- Schedule: `as_schedule_single_action( $timestamp, 'hook_name', $args )`89- Recurring: `as_schedule_recurring_action( $timestamp, $interval, 'hook_name', $args )`90- Handles retries, failure logging, and concurrent execution9192## Frontend Performance9394### Asset Loading9596- Conditionally load CSS/JS only on relevant pages97- Use `wp_enqueue_script` with `strategy => 'defer'` or `'async'`98- Combine/minify assets in production99- Use `wp_script_add_data( $handle, 'strategy', 'defer' )`100101### Cart Fragments102103AJAX cart fragment refreshing can be a bottleneck:104- Filter `woocommerce_cart_fragments` to minimize data105- Disable on pages where cart widget isn't shown106- Use `wc_cart_fragments_params` localized data107108### Image Optimization109110- Use WordPress responsive images (`srcset`, `sizes`)111- Enable lazy loading: `loading="lazy"` on product images112- Use WebP format where supported113- Configure image sizes: `add_image_size()` and WooCommerce image settings114115## Action Scheduler116117### Using Action Scheduler118119WooCommerce's built-in background job processor:120- `as_schedule_single_action( time(), 'my_hook', $args, 'my-group' )` — run once121- `as_schedule_recurring_action( time(), HOUR_IN_SECONDS, 'my_hook', $args )` — recurring122- `as_enqueue_async_action( 'my_hook', $args )` — ASAP execution123- `as_unschedule_action( 'my_hook', $args )` — cancel124- Monitor via WooCommerce > Status > Scheduled Actions125126### When to Use127128- Sending batch emails129- Syncing inventory with external systems130- Generating reports131- Processing large data imports/exports132- Cleaning up expired data133134## Best Practices135136- Enable HPOS for new stores and migrate existing ones137- Use persistent object cache (Redis/Memcached) in production138- Cache expensive computations and API responses with transients139- Use Action Scheduler for background processing — never process heavy tasks during HTTP requests140- Profile with Query Monitor plugin to identify slow queries141- Conditionally load assets only on pages where needed142- Use `wc_get_orders()` / `wc_get_products()` with appropriate limits143- Avoid N+1 query patterns — batch load related data144145Fetch the WooCommerce performance documentation and HPOS migration guide for exact configuration, migration steps, and optimization techniques before implementing.