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:
- Change description on specific WooCommerce product status change
- How to VAR_DUMP a $variable during checkout process (Is my product meta callable?)
- Using zip code to display custom data in Admin Order Details
- How do I get a function to work in single.php
- How to add product in woocommerce with php code [closed]
- How to update custom fields using the wp_insert_post() function?
- How to correctly add Javascript in functions.php
- How to check if a plugin (WooCommerce) is active?
- How to trigger WooCommerce order complete email?
- How to check if woocommerce is activated in theme
- How to get Woocommerce order product info
- Get meta_id along with meta_key and meta_value
- Woocommerce get selected shipping zone id for the current user
- Edit tag cloud widget number
- How to add date range in woocommerce with code
- How to automatically apply woocommerce product title to all product images alt tags?
- Remove Woocommerce product link
- Query WooCommerce orders grouped by several order statuses
- Creating custom Woocommerce attribute taxonomies from a plugin
- get product attributes for current product and store it in a variable
- How can merge two arrays values in one array and save in database
- Check if user already visited this post today
- Display sorting options dropdown when using WooCommerce product category shortcode
- Display all meta for a post?
- retrieve thumbnail from post ID of best selling product in category
- Display a selected custom product option in WooCommerce cart
- How to display multiple Post meta_key/meta_values by SQL query
- How to have a custom display for both woocommerce archive and product-category pages? [closed]
- WooCommerce: How to display item meta data in email confirmation using woocommerce_order_item_meta_end
- the_post_thumbnail() based on the Post ID
- How to get the original price of the product in woocommerce?
- How to use multiple query with same meta key
- Woocommerce auto cancel On-Hold after X days
- How to change “Shipping Calculator “field label on Cart Page – woocommerce? [closed]
- How to update single value in multi dimensional Post Meta?
- How to remove “out of stock” variation options from size dropdown in woocommerce?
- WP_Query | Help me create a search term with an ‘OR’ relation?
- Hide a menu-item and its submenus and display a ‘Log in’ link if the user is logged out
- Using Cookie Data For WP_Query Loop
- WooCommerce – Customer Order History Pagination
- How to get Woocommerce Variation ID? [closed]
- Cleanest/Fastest way to avoid calling and retrieving data from the database multiple times?
- Automatically check the option “Enable stock management at product level” on product creation
- The values of custom fields are not available functions.php
- How to show order data by multiple ID?
- Use wc_enqueue_js only on specific pages – nested add_action
- How to Remove a Filter from the Admin List Table?
- Why is my get_post_meta always empty
- Compare two meta key values against each other inside the get_posts array?
- How can update custom meta for all posts
- Problem with Woocommerce REST API Authentication
- Woocommerce: How to override core functions in functions.php?
- Woocommerce, recognize the loop of related products
- Replace existing content from specific WooCommerce admin orders list column
- Remove commas from WooCommerce checkout addresses fields
- Add product tag names to WooCommerce new order email subject
- WooCommerce Link to Product Category
- Remove General Tab and Plugin Tab in Settings in Woocommerce
- Get WooCommerce shipping methods programmatically
- WooCommerce – Display variation custom field value [closed]
- How to display product cropped thumbnail (150×150) for WooCommerce product categories
- Add a custom text field to WooCommerce admin product data “Variations”
- Add to checkout total lines an additional line below shipping in WooCommerce
- Woocommerce – How to get products which have a sale between 20% to 40%? [closed]
- Translating add to cart woocommerce button [closed]
- Use ajax to update_post_meta
- Output a WooCommerce product custom field in WooCommerce using get_post_meta()
- Append a term to WooCommerce product existing product category terms
- Woocommerce: Is it possible to overide the settings for allowing to purchase out of stock products [closed]
- Woocommerce HTML email option unavailable
- using woocommerce_template_single_add_to_cart in shop-loop – javascript issues [closed]
- How to add SVG icon above product tab title
- How does WooCommerce ensure that a product doesn’t run out of stock during payment? [closed]
- How To Change The Html of Products filtration sidebar in Woocommerce?
- Display related products with custom output
- How To add custom radio boxes to WooCommerce Billing page and change total price by this field?
- WooCommerce: update custom fields after checkout validation failure
- Add attribute / custom attribute to product in woocommerce
- Add multiple attributes to product from php
- Trigger Woocommerce New User Email
- Listing and displaying WooCommerce Shipping Zones in the frontend? [closed]
- Woocommerce filter cart and category specific quantity [closed]
- Use is_product_category() properly
- How to change / delete product short description in Woocommerce
- How to trash multiple post/product programmatically
- Writing scripts using WordPress / WooCommerce classes?
- My Own layout in WooCommerce pages [closed]
- How to get woocommerce cart content without an action?
- how to increase custom post value by one most efficiently?
- Batch update a post meta field value of each post in Post Type
- WooCommerce: Add Payment Gateway Field to Webhooks [closed]
- Woocommerce – remove product from category
- How to Display Image Meta underneath EVERY image in EVERY post
- How to make custom total price reactive in navigation
- Inject PHP code into “sidebar-content” – code before my WooCommerce sidebar widget?
- OrderItem get_total() returns lower value than $order_item->get_product()->get_price() * quantity
- Add the Name of Products Ordered to Admin New Order Email WooCommerce
- Changing Woocommerce flat rate every nth number of items
- How to prevent those PHP variables from being cached on WordPress?
- Woocommerce product download URL