A mechanism for improved filtering by attribute for variations was
introduced some time ago. This mechanism implied maintaining term
relationships for variations, where the terms were the attributes
that defined the variation.
The mechanism was reverted because it was complex and presented many
issues, but the code that created those term relationships was kept.
This pull request removes that code and the associated unit tests.
Product attributes are currently recorded as terms in
wp_term_relationships (product attributes are actually taxonomies).
In the case of variable products this is true for the main product,
but not for the variations. The attributes used to define variations
are stored as post meta, but nothing is recorded in the term
relationships table.
This is a problem when using the layered nav filtering plugin,
since the attribute counters displayed are calculated based solely
on the contents of the term relationships table. Adding meta queries
would be really messy (especially when the widget is configured
with AND operator) and would probably also hurt performance.
This commit adds a change to store the attributes for variations
as term relationships, additionally to storing them as post meta.
Terms are stored on variation creation, and updated/deleted together
with the variation as appropriate. "Any" variations (stored in meta
as empty values) are not stored as terms.
Additionally, a database upgrade is included in order to backfill
terms for already existing products.
The latest version of WPCS that was added to WC last week, changed the name of some sniffs. This commit updates the name of one of those sniffs from WordPress.WP.PreparedSQL.NotPrepared to WordPress.DB.PreparedSQL.NotPrepared.
I need a way to add my own pricing data to the variation data store, so I can check which price to display on the product and category pages, So instead of adding unnecessary load by leading each variation object to extract the data and meta I need, this gives me a way to get the data through the data store which in turns uses transients instead.
This commit adds product variation attributes to WP cache when they are first loaded to avoid running the same database queries when the same product is loaded multiple times. This cache will be invalidated whenever product attributes are changed.
Fixes#17120