problem when duplicate product in woocommerce
-
Hi,
Thanks for your plugin and thanks for your answers π
And by advance, sorry for my weird/funny english. I don’t write it or speak it very often.
So, I have a cptonomy my_author I associate with several post types, like blog posts, videos, links and products from woocommerce.
There is my 3 use cases:
1/ I gather all these informations in the single-my_author template with custom queries.
2/ I filter post type archives with my_author (?taxonomy=my_author&term=john-doe)
3/ I don’t use cpt_onomy_archive for now, but it’s niceThere is a problem with woocommerce when I duplicate a product in admin panel.
All the my_author terms that are associated with the product are added to the wp_terms table in the database, with the taxonomy my_author in wp_term_taxonomy table. Before that, there is no taxonomy that equals a post_type.
So, It changes the SQL query on all the 3 use cases.
It looks for posts that satisfy your “wp_postmeta.meta_key / _custom_post_type_onomies_relationship” condition (like before).
But it also add another statement based on “wp_term_relationships.term_taxonomy” with the fresh terms it just created.Of course, only the new (duplicate) product satisfy these 2 conditions, and after that, only post that I duplicate can satisfy them (or I have to associate manually my posts with those taxnomies).
So it breaks everything.
To solve this, you just have to remove these “wp” taxonomies from database, and behaviour is back to normal.
I add a silly filter to prevent that bug for now, it seems to work but I don’t know if it fits or not the plugin functioning ^^.
add_filter('pre_insert_term', function() { if (in_array($taxonomy, get_post_types())) return new WP_Error(); }, 10, 2);
Alright, thank you π
- The topic ‘problem when duplicate product in woocommerce’ is closed to new replies.