Stores the customer_user for WooCommerce orders and subscriptions in the post_author column of posts table.

Overview

Post Author Optimization for WooCommerce Testing status

  • Requires PHP: 7.0
  • WP requires at least: 5.7
  • WP tested up to: 5.7
  • WC requires at least: 5.6.0
  • WC tested up to: 5.8.0
  • Stable tag: 1.0.0
  • License: GPLv3 or later License

Description

This extension uses filters to store the _customer_user ID associated with a WooCommerce shop_order or shop_subscription in the post_author column. This allows for more efficent queries to get customer orders or subscriptions.

More information about this performance issue can be found in the WooCommerce development blog.

Props @pogla who wrote the majority of this code.

Details

WooCommerce stores order records in the posts table as a shop_order post type. The majority of data associated with the order, such as the order_total or billing and shipping information is stored in the postmeta table.

This works fine in most cases, but once a WooCommerce shop scales past ~1 million orders, queries of postmeta can start to run long. If WordPress needs to get a specific customer's orders (such as in the customer account dashboard), it requires a querying against _customer_user key in the postmeta table.

To see how long it takes on your site, you can run a query like this (use an actual customer id). If it returns in less than as second, it's probably not worth optimizing for at this point:

select * from wp_postmeta where meta_key = '_customer_user' and meta_value = 10;

This post on the WooCommerce developer blog explains the performance issue well, and also has a proposed solution! Why not use the post_author column in the posts table to store the customer ID? Querying against a much smaller table against an indexed column is much faster (as that post describes).

Unfortunately this idea was implemented and then reverted out of WooCommerce core. The reason is that sometimes a shop admin will create an order for a customer, and if the post_author column is used to store the customer ID, then there's no record of who actually created the order.

However, for the sites I work with, orders aren't generally created by admins. In the rare cases they are, an order note will be added. So we'll gladly take the performance improvements of storing the customer ID in the post_author column to make customer order queries more efficient.

In case you'd also like to make the switch, you can use this plugin. Once it's enabled, any future orders or subscriptions that are created or updated will save the _customer_user (ID) value to the post_author column in the posts table.

To update historic orders and subscriptions, you'll need to run a script or wp cli command (I'm still working on this).

The _customer_user meta will still be saved, so any queries that rely on it will continue to work. But, you can start to swap out those queries where needed to use the post_author column in the posts table instead.

You might also like...
The Laravel eCommerce USPS Shipping module allows the store owners to enable United States Postal Servies for the shipment of orders.

Introduction Bagisto Usps Shipping add-on provides Usps Shipping methods for shipping the product. By using this, you can provide Usps (United States

A hacky PHP script to download posts, images, videos and framework grading from Parent Zone

ParentZoneDownloader A hacky PHP script to download posts, images, videos and framework grading from Parent Zone Pre-Requisites Tested on PHP 7.4, but

Sync Wordpress Pages and Posts (even custom post types + fields) from static Markdown + YAML files

Sync Markdown Files to WordPress Posts and Pages Static site generators let you use a revision-controlled tree of markdown files to make a site, but d

Re-skinning BotCloaker enables you to add a SMART button at the end of all posts on your blog.

Re-skinning BotCloaker Wordpress Plugin Re-skinning BotCloaker enables you to add a SMART button at the end of all posts on your blog. Re-skinning Bot

Coder Metabox for WordPress - Create Pages, Posts Custom Meta Fields options

Coder Metabox for WordPress Coder Metabox for WordPress - Create Pages, Posts Custom Meta Fields options. Step 1 call coder-metabox.php file in functi

This is a class that allows you to import posts from Wix into WordPress.

Wix Posts to WordPress This is a class that allows you to import posts from Wix into WordPress. Requirements Please make sure you have the following i

Boostimer - Product Availability Countdown And Scheduler For Woocommerce

Boostimer - Product Availability Countdown And Scheduler For Woocommerce Contributors: zabiranik Donate link: zabiranik/donate Requires at least: 5.0

Custom code snippets and examples for SkyVerge-built WooCommerce extensions

SkyVerge WooCommerce Plugins Welcome to the wc-plugins-snippets repository! This repository stores code snippets related to SkyVerge WooCommerce plugi

WooCommerce function and class declaration stubs for static analysis.

WooCommerce Stubs This package provides stub declarations for WooCommerce functions, classes and interfaces. These stubs can help plugin and theme dev

Owner
Devin Price
Devin is a full-stack developer based in Austin, Texas. Building interesting things with WooCommerce @ Universal Yums.
Devin Price
YCOM Impersonate. Login as selected YCOM user 🧙‍♂️in frontend.

YCOM Impersonate Login as selected YCOM user in frontend. Features: Backend users with admin rights or YCOM[] rights, can be automatically logged in v

Friends Of REDAXO 17 Sep 12, 2022
Simple user settings facade for Hyperf. Settings are stored as JSON in a single database column, so you can easily add it to an existing table.

hyperf-user-settings Simple user settings util for hyperf Settings are stored as JSON in a single database column, so you can easily add it to an exis

lysice 1 Oct 15, 2021
Easily create WooCommerce replacement orders for your customers.

Support Orders for WooCommerce Requires PHP: 7.0 WP requires at least: 5.7 WP tested up to: 5.7 WC requires at least: 5.6.0 WC tested up to: 5.8.0 Sta

DevPress 5 Feb 24, 2022
The plugin generates posts/pages. Useful to generate millions of records in wp_posts table

KAGG Generator The plugin generates posts/pages. Useful to generate millions of records in wp_posts table. In WordPress development, sometimes it is n

Igor at KAGG Design 16 Jan 1, 2023
WooCommerce Empty Cart Button plugin helps you to add Empty Cart button to WooCommerce Pages/Sections using Shortcode only.

WooCommerce Empty Cart Button plugin helps you to add Empty Cart button to WooCommerce Pages/Sections using Shortcode only. How to use? Download the p

Katr 2 Sep 24, 2022
AMD module bundler and preloader for Magento 2 stores.

baler baler is an AMD module bundler and preloader for Magento 2 stores. Getting Started (Early Alpha) If you're willing to test alpha software, pleas

Magento 180 Nov 23, 2022
MailChimp for Magento 2. Syncs all data (subscriber, customers, orders, products) and enables marketing automation with email campaigns, automations, ads, postcards and more.

MailChimp for Magento 2. Syncs all data (subscriber, customers, orders, products) and enables marketing automation with email campaigns, automations, ads, postcards and more.

Mailchimp 139 Sep 9, 2022
Magento 2 module to quickly acces products, orders and customer from admin menu

Magento 2 module to quickly access product, order or customer views Introduction The Magento 2 backend can be sluggish. Ever wanted to access a produc

null 1 Dec 3, 2021
PHP 7+ Payment processing library. It offers everything you need to work with payments: Credit card & offsite purchasing, subscriptions, payouts etc. - provided by Forma-Pro

Supporting Payum Payum is an MIT-licensed open source project with its ongoing development made possible entirely by the support of community and our

Payum 1.7k Dec 27, 2022
Laravel Plans is a package for SaaS apps that need management over plans, features, subscriptions, events for plans or limited, countable features.

Laravel Plans Laravel Plans is a package for SaaS apps that need management over plans, features, subscriptions, events for plans or limited, countabl

ángel 2 Oct 2, 2022