diff --git a/assets/css/frontend.css b/assets/css/frontend.css index ae4374c..1cdf242 100644 --- a/assets/css/frontend.css +++ b/assets/css/frontend.css @@ -12,8 +12,6 @@ .single-product .product.type-yoone_bundle .images { display: none !important; } -/* 兼容通过 body_class 添加的标记 */ -.yoone-bundle-product div.images { display: none !important; } /* 表格列宽优化 */ .yoone-bundle-table th:nth-child(3), @@ -33,7 +31,8 @@ .yoone-bundle-items-wrapper { display: flex; flex-wrap: wrap; - gap: 20px; /* 卡片之间的间距 */ + gap: 1em; + margin: 1em; } .yoone-bundle-item-card { @@ -66,7 +65,6 @@ .yoone-bundle-item-card .item-price { font-size: 16px; - color: #c00; margin-bottom: 8px; } diff --git a/assets/js/frontend.js b/assets/js/frontend.js index 2413db5..dfd2590 100644 --- a/assets/js/frontend.js +++ b/assets/js/frontend.js @@ -1,3 +1,45 @@ -(function($){ - // 预留:如需在前端动态计算价格或增强交互,可在此添加脚本。 +(function($) { + 'use strict'; + + $(function() { + var minQty = 0; + var wrapper = $('.yoone-bundle-form'); + + // 从 DOM 中获取最小数量 + var minText = wrapper.find('.yoone-bundle-min').text(); + if (minText) { + var match = minText.match(/\d+/); + if (match) { + minQty = parseInt(match[0], 10); + } + } + + function updateState() { + var total = 0; + wrapper.find('.yoone-bundle-qty').each(function() { + var v = parseInt($(this).val(), 10); + if (!isNaN(v) && v > 0) { + total += v; + } + }); + + // 更新显示的数量 + wrapper.find('.yoone-bundle-selected-count').text(total); + + // 根据是否满足最小数量来启用/禁用按钮 + var btn = wrapper.find('.single_add_to_cart_button'); + if (total >= minQty) { + btn.prop('disabled', false); + } else { + btn.prop('disabled', true); + } + } + + // 绑定事件 + wrapper.on('change keyup', '.yoone-bundle-qty', updateState); + + // 页面加载时立即执行一次,以确保初始状态正确 + updateState(); + }); + })(jQuery); \ No newline at end of file diff --git a/includes/frontend/class-yoone-product-bundles-frontend.php b/includes/frontend/class-yoone-product-bundles-frontend.php index 248baab..df1402e 100644 --- a/includes/frontend/class-yoone-product-bundles-frontend.php +++ b/includes/frontend/class-yoone-product-bundles-frontend.php @@ -54,9 +54,6 @@ class Yoone_Product_Bundles_Frontend { // 加载插件内的完整页面模板 $new_template = YOONE_PB_PATH . 'templates/single-product-yoone-bundle.php'; if (file_exists($new_template)) { - // 加载前端资源 - if (wp_style_is('yoone-pb-frontend', 'registered')) wp_enqueue_style('yoone-pb-frontend'); - if (wp_script_is('yoone-pb-frontend', 'registered')) wp_enqueue_script('yoone-pb-frontend'); return $new_template; } } diff --git a/templates/single-product-yoone-bundle.php b/templates/single-product-yoone-bundle.php index 429464f..625e016 100644 --- a/templates/single-product-yoone-bundle.php +++ b/templates/single-product-yoone-bundle.php @@ -1,10 +1,11 @@ " > + +