In Woocommerce, How to find all products for which a certain product is a cross-sell?

390

You can do it with mysql query.

As WooCommerce stores crosssell IDs as serialized data - correct way seems to be reading all products via some WP loop and unserialize->analyze all crosssell IDs then search for the needed ID - but it would take too much time and memory.

That's why we need to find easier way - some trick. Here it is:

Assume ID of product A is 132, product B is 60, product C is 34.

And product A has 2 crosssell products - B and C.

So wp_postmeta table would have such row:

1098    132 _crosssell_ids  a:2:{i:0;i:60;i:1;i:34;}

Product B present's in other products' crossell_ids meta data as a "i:60;" unique string. That's why we just need to look for that string acroos all wp_postmeta.

global $wpdb;
$product_b_id=60;

$product_that_have_B_as_crossell= $wpdb->get_col("select post_id 
from $wpdb->postmeta 
where 
meta_key='_crosssell_ids' 
and
meta_value like  '%i:".esc_sql($product_b_id).";%' ");

var_dump($product_that_have_B_as_crossell);
Share:
390

Related videos on Youtube

ami rayne
Author by

ami rayne

Updated on December 11, 2022

Comments

  • ami rayne
    ami rayne over 1 year

    In Woocommerce, I would like to get a list of products that a certain product is defined as a cross-sell for them.

    So checking for which products B is a cross-sell would give: A, C

    Didn't find any background for this

    Example: product A has products B, C as cross sells Product B has products A, C, D as cross sells Product C has products A, B, D as cross sells

    So checking for which products B is a cross-sell would give: A, C

    • Simkill
      Simkill about 11 years
      Do you have more then 1 PCI-E 16x slots available for your graphics card? Could be a dodgy PCI-E slot.
    • Davidenko
      Davidenko about 11 years
      what motherboard?
    • Krogs
      Krogs about 11 years
      It's a Gigabyte X79-UD7 :)
    • Alvin Wong
      Alvin Wong about 11 years
      According to the manual of your motherboard, your board should have a debug LED. What is it saying?
    • Krogs
      Krogs about 11 years
      Ah yes, sorry, when I had just installed the new GPU, it was booting as uaual, untill the screen where I can choose to enter BIOS (which didn't work) The Debug Display shows code 64, which seems to be a memory issue, but that doesn't explain why my old GPU was broken.
  • Alvin Wong
    Alvin Wong about 11 years
    Really...? The OP says 1 long 3 short. Also I don't think every motherboards act the same.
  • Dave
    Dave about 11 years
    @AlvinWong Yes, I know it says 1 long and 3 short, and this can indicate either RAM or Video/Video RAM issue. See my updated Beep codes for different BIOS in link in my post.