Files
wc-composable-product/assets/js/admin.js
magdev ea2261d8d7 Refactor to PSR-4: rename files and switch namespace
- Rename files to PascalCase: Product_Type → ProductType, Cart_Handler →
  CartHandler, Product_Selector → ProductSelector, Stock_Manager →
  StockManager, Admin/Product_Data → Admin/ProductData
- Switch namespace from WC_Composable_Product to Magdev\WcComposableProduct
- Update all cross-references in PHP, CSS, JS, translations, and docs

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-01 12:35:02 +01:00

70 lines
2.2 KiB
JavaScript
Executable File

/**
* Admin JavaScript for Composable Products
*
* @package Magdev\WcComposableProduct
*/
(function($) {
'use strict';
$(document).ready(function() {
/**
* Show/hide product data tab for composable products
*/
$('select#product-type').on('change', function() {
const productType = $(this).val();
if (productType === 'composable') {
$('.show_if_composable').show();
$('.hide_if_composable').hide();
// Show the composable tab, then click it so WooCommerce's
// native tab system hides all other panels properly
$('.product_data_tabs li.composable_options').show();
$('ul.product_data_tabs li.composable_options a').trigger('click');
} else {
$('.show_if_composable').hide();
$('.product_data_tabs li.composable_options').hide();
$('#composable_product_data').hide();
}
}).trigger('change');
/**
* Toggle criteria groups based on selected type
*/
$('#_composable_criteria_type').on('change', function() {
const criteriaType = $(this).val();
$('.composable_criteria_group').hide();
$('#composable_criteria_' + criteriaType).show();
}).trigger('change');
/**
* Toggle fixed price field based on pricing mode
*/
function toggleFixedPriceField() {
const pricingMode = $('#_composable_pricing_mode').val();
const $fixedPriceField = $('.composable_fixed_price_field');
if (pricingMode === 'fixed') {
$fixedPriceField.show();
} else {
$fixedPriceField.hide();
}
}
$('#_composable_pricing_mode').on('change', toggleFixedPriceField);
toggleFixedPriceField();
/**
* Initialize enhanced select for categories and tags
*/
if ($.fn.selectWoo) {
$('#_composable_categories, #_composable_tags').selectWoo({
placeholder: 'Select options...',
allowClear: true
});
}
});
})(jQuery);