WordPress.org

Support

Support » Plugins and Hacks » problem when duplicate product in woocommerce

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 nice

    There 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 🙂

    http://wordpress.org/plugins/cpt-onomies/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Sorry, the code was not correct

    add_filter('pre_insert_term', function($term, $taxonomy) {
            if (in_array($taxonomy, get_post_types()))
                return new WP_Error();
            return $term;
        }, 10, 2);

    I didn’t find the time yet to dig into thi bug

    maricel0422
    Member

    @maricel0422

    Hi cjlmwmg,

    I am having a similar problem. Can you provide the name of the file you modified? Txs!

    esmi
    Forum Moderator

    @esmi

    @maricel0422: If you require assistance then, as per the Forum Welcome, please post your own topic.

    This 4 month old topic references an old version of WordPress.

    Hi,

    you can add this code in your functions.php or any other php file I think.
    I put mine in a file inside a personal plugin.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘problem when duplicate product in woocommerce’ is closed to new replies.