Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

Reverse Cross-Sells (WooCommerce)

You could do it with a meta query

$current_post_id = 'YOUR_POST_ID';

$args = array(
    'post_type' => 'product',
    'posts_per_page' => -1,
    'meta_query' => array(
        array(
            'key' => '_crosssell_ids',
            'value' => $current_post_id,
            'compare' => 'LIKE'
        )
    )
);

$query = new WP_Query($args);

if($query->have_posts()){
    while($query->have_posts()): $query->the_post();
        $product = wc_get_product(get_the_ID());

        // Do what you want with the product.
    endwhile;
}

This query will return all products that have the $current_post_id as a cross sell id.

Hope this helps.

Related Posts:

  1. Change description on specific WooCommerce product status change
  2. How to VAR_DUMP a $variable during checkout process (Is my product meta callable?)
  3. Using zip code to display custom data in Admin Order Details
  4. How do I get a function to work in single.php
  5. How to add product in woocommerce with php code [closed]
  6. How to update custom fields using the wp_insert_post() function?
  7. How to correctly add Javascript in functions.php
  8. How to check if a plugin (WooCommerce) is active?
  9. How to trigger WooCommerce order complete email?
  10. How to check if woocommerce is activated in theme
  11. How to get Woocommerce order product info
  12. Get meta_id along with meta_key and meta_value
  13. Woocommerce get selected shipping zone id for the current user
  14. Edit tag cloud widget number
  15. How to add date range in woocommerce with code
  16. How to automatically apply woocommerce product title to all product images alt tags?
  17. Remove Woocommerce product link
  18. Query WooCommerce orders grouped by several order statuses
  19. Creating custom Woocommerce attribute taxonomies from a plugin
  20. get product attributes for current product and store it in a variable
  21. How can merge two arrays values in one array and save in database
  22. Check if user already visited this post today
  23. Display sorting options dropdown when using WooCommerce product category shortcode
  24. Display all meta for a post?
  25. retrieve thumbnail from post ID of best selling product in category
  26. Display a selected custom product option in WooCommerce cart
  27. How to display multiple Post meta_key/meta_values by SQL query
  28. How to have a custom display for both woocommerce archive and product-category pages? [closed]
  29. WooCommerce: How to display item meta data in email confirmation using woocommerce_order_item_meta_end
  30. the_post_thumbnail() based on the Post ID
  31. How to get the original price of the product in woocommerce?
  32. How to use multiple query with same meta key
  33. Woocommerce auto cancel On-Hold after X days
  34. How to change “Shipping Calculator “field label on Cart Page – woocommerce? [closed]
  35. How to update single value in multi dimensional Post Meta?
  36. How to remove “out of stock” variation options from size dropdown in woocommerce?
  37. WP_Query | Help me create a search term with an ‘OR’ relation?
  38. Hide a menu-item and its submenus and display a ‘Log in’ link if the user is logged out
  39. Using Cookie Data For WP_Query Loop
  40. WooCommerce – Customer Order History Pagination
  41. How to get Woocommerce Variation ID? [closed]
  42. Cleanest/Fastest way to avoid calling and retrieving data from the database multiple times?
  43. Automatically check the option “Enable stock management at product level” on product creation
  44. The values of custom fields are not available functions.php
  45. How to show order data by multiple ID?
  46. Use wc_enqueue_js only on specific pages – nested add_action
  47. How to Remove a Filter from the Admin List Table?
  48. Why is my get_post_meta always empty
  49. Compare two meta key values against each other inside the get_posts array?
  50. How can update custom meta for all posts
  51. Problem with Woocommerce REST API Authentication
  52. Woocommerce: How to override core functions in functions.php?
  53. Woocommerce, recognize the loop of related products
  54. Replace existing content from specific WooCommerce admin orders list column
  55. Remove commas from WooCommerce checkout addresses fields
  56. Add product tag names to WooCommerce new order email subject
  57. WooCommerce Link to Product Category
  58. Remove General Tab and Plugin Tab in Settings in Woocommerce
  59. Get WooCommerce shipping methods programmatically
  60. WooCommerce – Display variation custom field value [closed]
  61. How to display product cropped thumbnail (150×150) for WooCommerce product categories
  62. Add a custom text field to WooCommerce admin product data “Variations”
  63. Add to checkout total lines an additional line below shipping in WooCommerce
  64. Woocommerce – How to get products which have a sale between 20% to 40%? [closed]
  65. Translating add to cart woocommerce button [closed]
  66. Use ajax to update_post_meta
  67. Output a WooCommerce product custom field in WooCommerce using get_post_meta()
  68. Append a term to WooCommerce product existing product category terms
  69. Woocommerce: Is it possible to overide the settings for allowing to purchase out of stock products [closed]
  70. Woocommerce HTML email option unavailable
  71. using woocommerce_template_single_add_to_cart in shop-loop – javascript issues [closed]
  72. How to add SVG icon above product tab title
  73. How does WooCommerce ensure that a product doesn’t run out of stock during payment? [closed]
  74. How To Change The Html of Products filtration sidebar in Woocommerce?
  75. Display related products with custom output
  76. How To add custom radio boxes to WooCommerce Billing page and change total price by this field?
  77. WooCommerce: update custom fields after checkout validation failure
  78. Add attribute / custom attribute to product in woocommerce
  79. Add multiple attributes to product from php
  80. Trigger Woocommerce New User Email
  81. Listing and displaying WooCommerce Shipping Zones in the frontend? [closed]
  82. Woocommerce filter cart and category specific quantity [closed]
  83. Use is_product_category() properly
  84. How to change / delete product short description in Woocommerce
  85. How to trash multiple post/product programmatically
  86. Writing scripts using WordPress / WooCommerce classes?
  87. My Own layout in WooCommerce pages [closed]
  88. How to get woocommerce cart content without an action?
  89. how to increase custom post value by one most efficiently?
  90. Batch update a post meta field value of each post in Post Type
  91. WooCommerce: Add Payment Gateway Field to Webhooks [closed]
  92. Woocommerce – remove product from category
  93. How to Display Image Meta underneath EVERY image in EVERY post
  94. How to make custom total price reactive in navigation
  95. Inject PHP code into “sidebar-content” – code before my WooCommerce sidebar widget?
  96. OrderItem get_total() returns lower value than $order_item->get_product()->get_price() * quantity
  97. Add the Name of Products Ordered to Admin New Order Email WooCommerce
  98. Changing Woocommerce flat rate every nth number of items
  99. How to prevent those PHP variables from being cached on WordPress?
  100. Woocommerce product download URL
Categories PHP Tags get-the-id, php, post-meta, woocommerce-offtopic
ACF background-color per post in a WordPress loop
Custom permalink gives 404 error only in some pages

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress