get_type() !== Yoone_Product_Bundles::TYPE) { 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']; // 收集允许的商品对象,且必须是 simple product $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)) { 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)) { $groups[$t->term_id]['term'] = $t; $groups[$t->term_id]['items'][] = $p; $matched = true; } } } // 若商品不属于所选分类,则不显示 if (! $matched) { // 跳过 } } } else { $groups[0] = array('term' => null, 'items' => array_values($allowed_products)); } // 表单开始 ?>

0

$group) : ?>

name); ?>

get_id(); ?>
get_name()); ?> get_price_html()); ?>