Causes and ways to fix slow Woocommerce product posting

Nguyên nhân và cách khắc phục đăng sản phẩm Woocommerce bị chậm

There are a few common reasons why duplicating and then publishing a WooCommerce product is slow — usually because the server/WordPress has to do a lot of heavy lifting each time the product is “saved/published.” Below I list the possible causes in order of priority, along with how to check + specific fixes for you to implement immediately.

Common causes (and how to quickly check/fix)

  1. Sản phẩm có nhiều biến thể / thuộc tính / biến thể cực lớn
    • Check: variant products > 50-100 items are very heavy to save/publish (create a lot of postmeta).
    • Solution: temporarily test with 1 copy with few variations; If so, think about optimizing the variation (using a simpler variation or a separate product).
  2. Rất nhiều postmeta cho sản phẩm (meta bùng nổ)
    • Kiểm tra nhanh bằng WP-CLI / MySQL: wp db query "SELECT COUNT(*) AS cnt FROM wp_postmeta WHERE post_id = 12345;" (thay 12345 bằng ID sản phẩm).
    • If count is very large (> several thousand) → this is a problem. Check which plugins add meta (e.g. feature plugins, analytics, custom fields).
    • Fix: delete excess meta, or refactor the plugin to not save too much meta.
  3. Regenerate / tạo thumbnails ảnh (nhiều kích thước) khi publish
    • Reason: when copying/publishing, WP may call the process to create thumbnails for each size (theme + plugin adds size) — with large image files or many images, it is slow.
    • Kiểm tra: xem log PHP/nginx, sẽ thấy wp_generate_attachment_metadata chạy.
    • Temporary fix (no thumbnails generated when testing):
    • Long-term side: reduce image sizes, use background image processing (plugin regenerate thumbnails queue), offload images to CDN/S3.
add_filter('intermediate_image_sizes_advanced', '__return_empty_array'); (đặt tạm vào theme/plugin; nhớ remove sau test).
  1. Plugin gây delay khi hook vào save_post / transition_post_status / wp_insert_post
    • Test: turn off all plugins (except WooCommerce), try copying/publishing — if it's fast again, turn it on one by one to find the slow plugin.
    • Fix: fix that plugin or separate heavy work to the background (wp_cron/asynchronous).
  2. Webhooks / API gọi ra ngoài khi publish (Google Merchant, Zalo, Facebook, inventory sync, GA, ERP)
    • Check: see if the plugin sets a webhook or sends a request when publishing; Check access log/ application log.
    • Solution: switch to asynchronous webhook sending (queue) or temporarily disable.
  3. WP-Cron / cron job đang chạy nặng hoặc bị block
    • Kiểm tra: bật DISABLE_WP_CRON và chạy cron thủ công bằng WP-CLI để xem.
    • Fix: switch WP-Cron to system cron, optimize cron tasks.
  4. Database chậm / thiếu index / table bị lock
    • Kiểm tra: xem SHOW PROCESSLIST; khi publish để xem query nào chậm, hoặc bật slow_query_log của MySQL.
    • Fix: optimize query, add index, configure MySQL, increase RAM, or optimize wp_postmeta table (partition/cleanup).
  5. Server thiếu tài nguyên (CPU, RAM) — PHP-FPM timeout / swap thrashing
    • Kiểm tra: khi publish chạy top/htop hoặc dùng monitoring; check logs PHP-FPM/nginx.
    • Fix: increase memory_limit, increase PHP workers, upgrade VPS, or optimize plugin to reduce consumption.
  6. Object cache / Redis issues
    • If the object cache is misconfigured, it can cause blocking when setting/get cache. Check Redis connection, object-cache plugin.
    • Fix: check Redis plugin, logs, try temporarily disabling object cache.
  7. Revisions/autosave quá nhiều / size post content lớn
    • Kiểm tra số revisions: SELECT COUNT(*) FROM wp_posts WHERE post_parent = 12345 AND post_type = 'revision';
    • Fix: limit revisions, delete old revisions.

Checklist for step-by-step debugging (execute immediately)

  1. Bật debug để biết rõ
    file wp-config.php: define('WP_DEBUG', true); define('WP_DEBUG_LOG', true); // check wp-content/debug.log define('WP_DEBUG_DISPLAY', false);
  2. Test nhanh bằng tắt plugin
    • Disable all plugins except WooCommerce + default theme (Twenty*). If fast → enable each plugin to find the culprit.
  3. Kiểm tra process khi publish
    • Dùng tail -f /var/log/nginx/error.log + tail -f wp-content/debug.log khi bạn click Publish để thấy lỗi/slow function.
  4. Kiểm tra số meta (WP-CLI): wp db query "SELECT COUNT(*) cnt FROM wp_postmeta WHERE post_id = PRODUCT_ID;"
  5. Kiểm tra HTTP calls (nếu nghi có webhook): xem access log hoặc cài plugin Query Monitor (chạy trên môi trường staging vì Query Monitor nặng).
  6. Kiểm tra ảnh: thử vô media, mở ảnh đó — nếu ảnh rất lớn (20MB+) thì đó là nguyên nhân.
  7. Chạy slow query log MySQL nếu cần (server-level).

Some useful commands/codes you can run right away

  • See slow hooks when publishing (temporarily log time):
add_action('transition_post_status', function($new, $old, $post){
    if($post->post_type !== 'product') return;
    $log = sprintf("[%s] transition_post_status %s -> %s for %dn", date('c'), $old, $new, $post->ID);
    error_log($log);
}, 10, 3);
  • Delete all transients (test):
wp transient delete --all
  • Check cron queue:
wp cron event list

Long-term optimal measures (once the cause has been determined)

  • Run thumbnail generation asynchronously (plugin queue or background worker).
  • Offload media to S3/Cloudflare R2 + CDN.
  • Use properly configured object cache (Redis).
  • Reduce the number of image sizes registered by the theme/plugin.
  • Refactor plugin / custom code: instead of doing heavy work synchronously on save_post → push to queue (Action Scheduler, wp_cron system or RabbitMQ). WooCommerce recommends Action Scheduler for background tasks.
  • Optimize database (index, cleanup postmeta, optimize tables).
Categories: WooCommerce Wordpress

mrhai

Để lại bình luận