Gostaria que "Gerenciar estoque" fosse verificado por padrão no woocommerce APENAS assim que criar uma nova variação (um filho é adicionado a .woocommerce_variations.wc-metaboxes.ui-sortable), mas meu código não vale a pena
add_action( 'admin_footer', 'custom_admin_product_variations_js' );
function custom_admin_product_variations_js() {
global $post_type;
if ( 'product' === $post_type ) :
?><script type='text/javascript'>
jQuery(function ($) {
// Function to handle changes in the DOM
function handleDOMChanges(mutationsList, observer) {
$('#variable_product_options').on('change', function () {
$('input.variable_manage_stock').each(function () {
if (!$(this).is(':checked')) {
$(this).attr('checked', 'checked').closest('div').find('.wc_input_stock').val(1);
}
});
});
}
// Create a MutationObserver
const targetNode = document.querySelector('.woocommerce_variations.wc-metaboxes.ui-sortable');
const config = { childList: true, subtree: true };
const observer = new MutationObserver(handleDOMChanges);
// Start observing changes in the DOM
observer.observe(targetNode, config);
});
</script><?php
endif;
}
Já tentei todas as postagens no stackoverflow sobre esse problema específico.