stuttter/wp-term-images

conflict with the WooCommerce 'product_cat' taxonomy on the edit-tags.php screen

pbiron opened this issue · 1 comments

I'm evaluating using this plugin on a WooCommerce site I'm building.

Woo already has built-in support for adding images to it's product_cat taxonomy. And I want to add images to Woo's product_tag taxonomy...and that works fine.

However, there's a conflict with WP_Term_Meta_UI::term_clauses() and the way Woo alters what is returned by get_terms().

Woo provides a drag-and-drop UI on the edit screen for the product_cat taxonomy that allows a user to specify a sort order for the terms in that tax on the front end. It stores that order order as term meta. By default, it orders to terms in the terms list table by that sort order...as such it adds 'orderby' => 'meta_value_num' (thru some filter, I forget which at the moment).

Unfortunately, when WP_Term_Meta_UI::term_clauses() sees 'orderby' => 'meta_value_num' it joins to the term meta table and alters the where clause such that only terms with the image meta key are return. This results in 0 terms being found, even tho the list table realizes there are terms in the taxonomy as evidenced by the highlighted numbers in this screenshot.

no-product-cats-found

[Note: the Image column in that screenshot is Woo's built-in column, and not the one added by this plugin. I have hooked into wp_term_image_get_taxonomies and restricted the taxonomies this plugin adds the Image column on to Woo's product_tag tax.]

As a workaround I tried to unhook WP_Term_Meta_UI::term_clauses() and WP_Term_Meta_UI::get_terms_orderby() from terms_clauses and get_terms_orderby respectively since I don't want the Image column to be sortable anyway. I'm hooking into manage_edit-product_tag_sortable_columns to remove the Image column this plugin adds from the sortable columns (to match the fact that Woo's built-in Image column for the product_cat taxonomy isn't sortable). However, since there is no global variable for that object I can't do that.

I bet Woo isn't the only thing that will conflict with allowing 'orderby' => 'meta_value_num' to cause the join/where modifications that WP_Term_Meta_UI::term_clauses() does.

Knowing you, I'm sure there's a good reason for having meta_value_num in $allowed_keys even tho this plugin doesn't ever key that as an orderby, but for the life of me I can't figure out why :-) This plugin seems to work just fine if I remove meta_value_num from $allowed_keys.

This is still an issue. If you activate this plugin with WooCommerce all your categories disappear from Products > Categories. Deactivating it will bring them back.