Custom script doesn’t work in admin
-
Hello,
i have added a custom script file in admin , for change background color in variation “Stock status” selectThis is the code for enqueue the file in my child-theme
function epd_custom_admin_script($hook) { if( 'post.php' != $hook ) return; wp_register_script( 'custom-admin-script', get_stylesheet_directory_uri() . '/js/custom-admin-script.js', array('jquery'), '1.0', true); wp_enqueue_script( 'custom-admin-script' ); } add_action( 'admin_enqueue_scripts', 'epd_custom_admin_script' );
This is the script code
jQuery(document).ready(function ($) { var select = $('.hide_if_variation_manage_stock select'); select.on('change', function () { var ss = $(this).val(); if (ss === 'instock') { select.css('background', 'green'); } else if (ss === 'outofstock') { select.css('background', 'red'); } else if (ss === 'onbackorder') { select.css('background', 'yellow'); } }); });
the code does not work, but if I try the console, the code works fine as you can see here screenshot
someone can help me understand why?
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Custom script doesn’t work in admin’ is closed to new replies.