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 automatically apply woocommerce product title to all product images alt tags?
- How to have a custom display for both woocommerce archive and product-category pages? [closed]
- WP_Query | Help me create a search term with an ‘OR’ relation?
- WooCommerce – Customer Order History Pagination
- The values of custom fields are not available functions.php
- Replace existing content from specific WooCommerce admin orders list column
- Woocommerce – How to get products which have a sale between 20% to 40%? [closed]
- Woocommerce filter cart and category specific quantity [closed]
- How to get woocommerce cart content without an action?
- how to increase custom post value by one most efficiently?
- WooCommerce: Add Payment Gateway Field to Webhooks [closed]
- How to Display Image Meta underneath EVERY image in EVERY post
- Woocommerce product download URL
- Limiting woocommerce line_total decimal length
- How can I use wp_query to show all product data using just the products ID?
- write custom woocommerce templates and forms
- Get Current User Id Inside a Loop Returns 0 For a Shortcode
- Get stock by custom meta field on all Woocommerce variable products
- Set a condition based on WooCommerce checkout city field while placing order
- WooCommerce – Email admin with new user details
- Call global variable array() in woocommerce child/template
- Remove price from Woocommerce variable product dropdown menu
- Advanced Meta Query for Large Calendar Website (12k+ posts) (175k+ wp_postmeta rows)
- Issue adding sub category programmatically
- Get and insert order email address to the PHP template inside HTML text
- If no products are on sale – hide ID or class
- do search in two site and show the result in first site
- How can I pass a custom/dynamic product to the Woocommerce cart?
- How to get private property in parent class into extended class?
- Replace Woocommerce “add to cart” to be “Download” button [closed]
- Woocommerce Email attachments not working – file not being attached
- Add post with approval by the admin
- Querying Database with wpdb
- How to optimize update_post_meta?
- WooCommerce pages looks unstyled
- How to display a custom product field value of a specific category on a Woo Commerce checkout page?
- Personalize checkout text
- CSS change in woo commerce Place Order Text [closed]
- Disable if there are no children – Woocommerce
- Exclude product attributes from taxonomy terms loop
- WP All Import / Update stock quantity from multiple XML files
- Add category to post meta
- Alter Woocommerce product archive structure
- Custom Taxonomy Select Menu: Setting default option value?
- Unable to Call More than One Meta Box Output
- Hide a div when a custom field is empty
- Post meta select input, if statement
- WordPress stripping out custom field tags
- Woocommerce Custom Meta Boxes- How to only display if they actually have content
- Display Sibling WooCommerce Product Categories on Archive Page
- Modify WooCommerce used to get all orders in dashboard
- How to sort WooCommerce products page by latest in-stock items first?
- WP_Query for woocommerce products with a pattern as a post_title
- Generate images with html2canvas and the woocommerce api
- How to update ticket price programatically when adding to cart and checkout in woocommerce
- Woocommerce My acount page
- Get WooCommerce products with similar SKU
- Woocommerce display orders with products from specific categories to specific admins
- Use CSS tag inside PHP code
- Set ACF on order during checkout
- Hide payment method based on user role AND minimum cart value
- How can I show how much water got saved on this order (making use of the number of items bought) on a thank-you-page?
- IF statement not working – Any suggestions?
- Don’t update modified post date when user add a product review or comment?
- Delete post meta by serialized meta value
- How do I change the “login” label in My Account page to “Registered Customer”
- Customize the “Available for back order” text for specific variation
- WooCommerce function not working correctly after moving from the functions.php into a class
- Filter for product subcategory listing page load
- Reduce Stock Based on Custom Variation Field Rather than Attribute (Working Script)
- Get x numbers of a woocommerce category products using Wp_Query
- Get field value and use as variable in php
- Set notification if is two product category in cart
- How to add custom attribute to all outofstock and all instock products automatically?
- Site infected by link
- Show a text if the post has written by author user role in WordPress
- AJAX to add to cart multiple products woocommerce
- sessionStorage saves input value in browser but it is not loaded in the form field
- Remove item from post_meta array via AJAX
- WooCommerce – Add Shipping class below each product in Shopping Cart page
- Hide price excluding tax when price is empty
- WooCommerce Custom Tab with ACF Repeater Field
- Display product attributes for current product
- How to remove image on single product and get product to span page?
- Postmeta not saving
- If custom field doesn’t exist, or exists and it’s true show title?
- Adding placeholder text field to woocommerce checkout [closed]
- Getting custom field data from cart page to checkout page in woocomerce [closed]
- Send a custom notification to customer on WooCommerce cancelled order status
- How to code bulk order form in wordpress
- Custom field fetch error on woocommerce pdf invoice
- posts_clauses drop ACF get_field function
- Grabbing value of input field inside of array
- How to set variable to specific field when querying
- WooCommerce Checkout Cart [closed]
- Woocommerce – add tracking code to another email template