the task is fairly “simple”, but I am annoyed with it for whole today. In Woocommerce admin order preview, I want to change class, to the number, where quantity is greater than 1.
For this purpose, I have made following things.
- Loaded the script (if I open developer console, the pathway is correct):
add_action( 'admin_enqueue_scripts', 'add_my_script' );
function add_my_script() {
wp_enqueue_script( 'jqueryforadmin', get_stylesheet_directory_uri().'/js/wp-admin.js');
}
- In the wp-admin.js I have added the jQuery code:
jQuery(document).ready(function($) {
$('.wc-order-preview-table__column--quantity').filter(function(index){
return parseInt(this.innerHTML) > 1;
}).css({'color':'blue', 'text-decoration':'underline'});
});
The problem is that the code doesn’t work. I remember, that the order preview is loaded via Ajax. Not even sure, if the code is right (because of the compatability mode I am not familiar with). Is there any way to make it work?
2
Answers
Finally figured it out
1) I forgot to include jQuery as dependency as suggested by thingEvery.
2) The trick was in using
.ajaxComplete
You need to include jquery as a dependency.
wp_enqueue_script( 'jqueryforadmin', get_stylesheet_directory_uri().'/js/wp-admin.js', array( 'jquery' ) );
wp_enqueue_script