__('混装产品', 'yoone-product-bundles'), 'target' => 'yoone_bundle_data', 'class' => array('show_if_yoone_bundle'), // 仅当类型为 yoone_bundle 时显示 'priority' => 70, ); return $tabs; } public function render_product_data_panel() { global $post; $product = wc_get_product($post->ID); $config = Yoone_Product_Bundles::get_bundle_config($product); $allowed = $config['allowed_products']; $min_qty = $config['min_qty']; $cats = $config['categories']; echo '
'; // panel } public function save_product_meta($post_id) { $product = wc_get_product($post_id); if (! $product || $product->get_type() !== Yoone_Product_Bundles::TYPE) return; // 保存 allowed products $allowed = isset($_POST['yoone_bundle_allowed_products']) ? (array) $_POST['yoone_bundle_allowed_products'] : array(); $allowed = array_values(array_filter(array_map('absint', $allowed))); update_post_meta($post_id, Yoone_Product_Bundles::META_ALLOWED_PRODUCTS, $allowed); // 保存 min qty $min_qty = isset($_POST['yoone_bundle_min_quantity']) ? absint($_POST['yoone_bundle_min_quantity']) : 0; update_post_meta($post_id, Yoone_Product_Bundles::META_MIN_QTY, max(0, $min_qty)); // 保存 categories $cats = isset($_POST['yoone_bundle_categories']) ? (array) $_POST['yoone_bundle_categories'] : array(); $cats = array_values(array_filter(array_map('absint', $cats))); update_post_meta($post_id, Yoone_Product_Bundles::META_CATEGORIES, $cats); } }