Support » Plugin: WooCommerce » Product/category correlations in WP/Woo database

  • Resolved zhuzh1

    (@zhuzh1)


    while working a plugin, I need to find how are product<–>Category correlations stored in WP/Woo database.

    So far, I found product info in wp_posts & category info in wp_terms table, but am having difficulty of linking products with categories in database.

    I am also trying to find category<–>vendor correlations without any success. I have installed Woo’s product-vendor plugin.

    Thanks
    JZ

    • This topic was modified 2 years, 3 months ago by zhuzh1.
    • This topic was modified 2 years, 3 months ago by zhuzh1.

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support Hannah S. a11n

    (@fernashes)

    Automattic Happiness Engineer

    Hey there!

    while working a plugin, I need to find how are product<–>Category correlations stored in WP/Woo database.

    So far, I found product info in wp_posts & category info in wp_terms table, but am having difficulty of linking products with categories in database.

    Can you tell me a bit more about what you’re looking for, i.e. how you need to use the information? That’ll help me try to answer your question.

    I am also trying to find category<–>vendor correlations without any success. I have installed Woo’s product-vendor plugin.

    I’ve addressed this question in your other thread:
    https://wordpress.org/support/topic/woo-category-vendor-or-product-vendor-correlations/

    Let’s continue the discussion there. 🙂

    Stef

    (@serafinnyc)

    I think they’re looking for which table do the Categories exist in @fernashes

    If that’s correct @zhuzh1 they reside in wp_term_taxonomy

    This is a break down of the tables inside the database with relation to WooCommerce. Product types, categories, subcategories, tags, attributes and all other custom taxonomies are located in the following tables:

    wp_terms
    wp_termmeta
    wp_term_taxonomy
    wp_term_relationships
    wp_woocommerce_termmeta

    wp_woocommerce_attribute_taxonomies
    (for product attributes only)

    Thread Starter zhuzh1

    (@zhuzh1)

    @serafinnyc, @fernashes

    Thanks for your insights and responses which helped a lot.

    Eventually, I used the following query to retrieve corresponding vendor_id and category_id by the post_id for the product (for those who have not dived deep in Woo: products are stored in wp_posts table where post_type=’product’):

    select t.term_taxonomy_id, t.taxonomy
    from wp_term_taxonomy as t, wp_term_relationships as r
    where
    r.term_taxonomy_id=t.term_taxonomy_id and
    t.taxonomy in (‘product_cat’, ‘wcpv_product_vendors’) and
    r.object_id=1051;

    in the query, 1051 is post_id/product_id. The result is, hopefully, self-explanatory:

    term_taxonomy taxonomy
    ————- ——–
    23 wcpv_product_vendors
    44 product_cat

    • This reply was modified 2 years, 2 months ago by zhuzh1.
    Stef

    (@serafinnyc)

    Awesome. Thank you for sharing. Have a great day.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Product/category correlations in WP/Woo database’ is closed to new replies.