可以通过元查询来实现
$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;
}
此查询将返回所有具有$current\\u post\\u id作为交叉销售id的产品。
希望这有帮助。