get_type() !== Yoone_Product_Bundles::TYPE) { // 如果不是,则回退到标准模板 wc_get_template_part('content', 'single-product'); return; } // --- 数据准备逻辑 --- $config = Yoone_Product_Bundles::get_bundle_config($product); $allowed = $config['allowed_products']; $min_qty = max(0, absint($config['min_qty'])); $cat_ids = $config['categories']; $allowed_products = array(); foreach ($allowed as $pid) { $p = wc_get_product($pid); if ($p && $p->is_type('simple')) { $allowed_products[$pid] = $p; } } $groups = array(); if (!empty($cat_ids)) { $others = array(); foreach ($allowed_products as $pid => $p) { $terms = get_the_terms($pid, 'product_cat'); $matched = false; if (is_array($terms)) { foreach ($terms as $t) { if (in_array($t->term_id, $cat_ids, true)) { if (!isset($groups[$t->term_id])) { $groups[$t->term_id] = array('term' => $t, 'items' => array()); } $groups[$t->term_id]['items'][] = $p; $matched = true; } } } if (!$matched) $others[] = $p; } if (!empty($others)) $groups[0] = array('term' => null, 'items' => $others); } else { $groups[0] = array('term' => null, 'items' => array_values($allowed_products)); } // --- 数据准备逻辑结束 --- get_header('shop'); ?>