Yoone Product Bundles 需要启用 WooCommerce。

'; }); return; } // 插件常量(路径) define('YOONE_PB_PATH', plugin_dir_path(__FILE__)); define('YOONE_PB_URL', plugin_dir_url(__FILE__)); // 自动加载(简单版):按需引入类文件 require_once YOONE_PB_PATH . 'includes/class-yoone-product-bundles.php'; require_once YOONE_PB_PATH . 'includes/class-yoone-product-type-bundle.php'; require_once YOONE_PB_PATH . 'includes/admin/class-yoone-product-bundles-admin.php'; require_once YOONE_PB_PATH . 'includes/frontend/class-yoone-product-bundles-frontend.php'; // 引导插件 add_action('plugins_loaded', function () { // 注册产品类型 Yoone_Product_Bundles::instance(); Yoone_Product_Bundles_Admin::instance(); Yoone_Product_Bundles_Frontend::instance(); }); // 插件版本号 define('YOONE_PB_VERSION', '0.1.1'); // 资源加载(前端样式/脚本) add_action('wp_enqueue_scripts', function () { wp_register_style('yoone-pb-frontend', YOONE_PB_URL . 'assets/css/frontend.css', array(), YOONE_PB_VERSION); wp_register_script('yoone-pb-frontend', YOONE_PB_URL . 'assets/js/frontend.js', array('jquery'), YOONE_PB_VERSION, true); }); // 后台资源 add_action('admin_enqueue_scripts', function ($hook) { // 仅在产品编辑页加载(post.php/post-new.php 且 post_type=product) if (strpos($hook, 'post.php') !== false || strpos($hook, 'post-new.php') !== false) { $screen = get_current_screen(); if ($screen && 'product' === $screen->post_type) { wp_enqueue_style('woocommerce_admin_styles'); wp_enqueue_script('wc-product-search'); // Woo 的 select2 产品搜索 wp_enqueue_style('yoone-pb-admin', YOONE_PB_URL . 'assets/css/admin.css', array(), YOONE_PB_VERSION); wp_enqueue_script('yoone-pb-admin', YOONE_PB_URL . 'assets/js/admin.js', array('jquery'), YOONE_PB_VERSION, true); } } }); // 激活钩子:无需建表,使用 postmeta 保存配置;此处可预置默认值或做数据迁移 register_activation_hook(__FILE__, function () { // 预留:未来若需要自定义 DB 表,可在此创建。 });