Where to find a complete list of Javascript (JQuery) events that fire on the WooCommerce admin page?
Answer a question
Where to find a complete list of Javascript (JQuery) events that fire on the WooCommerce admin page?
For example, if you wanted to run a Javascript function after adding a new attribute to a product from the product edit page, which event should you use?
The answer to this question only reports events in the WooCommerce frontend.
Answers
Javascript events for WooCommerce admin can be found in the directory:
/wp-content/plugins/woocommerce/assets/js/admin
If you want to use JQuery in the Wordpress admin remember to load your script after JQuery is loaded.
Look at these answers:
- How can I include JavaScript that use jQuery on admin side
- get_template_directory_uri pointing to parent theme not child theme
Make sure you set the
$in_footerparameter to true for thewp_enqueue_scriptfunction otherwise the events may not be triggered in the Wordpress admin pages.
For more details:
- jQuery.on() does not work in WordPress admin panel
META BOXES ORDER
quantity_changedtriggered when the quantity of the order item line changes (and after updating the totals and taxes of the line)order-totals-recalculate-beforetriggered before sending Ajax request to recalculate totals (after clicking "Recalculate")order-totals-recalculate-successtriggered when the Ajax request was successful (after clicking "Recalculate")order-totals-recalculate-completetriggered when the Ajax request has completed (after clicking "Recalculate")items_savedtriggered after clicking on "Save" and sent the Ajax requestrefund_quantity_changedtriggered when you change the quantity of a product to be refunded
META BOXES PRODUCT VARIATON
wc-enhanced-select-initrun actions when variations is loaded (on product edit page)woocommerce_variations_loadedtriggered after loading variations via Ajax (on product edit page)woocommerce_variations_savedtriggered after saving changes to variations via Ajaxwoocommerce_variations_save_variations_buttontriggered after clicking on the "Save changes" buttonwoocommerce_variations_save_variations_on_submittriggered after clicking on the "Update" button instead of "Save changes"woocommerce_variations_addedtriggered after adding a variationwoocommerce_variations_removedtriggered after removing a variationwoocommerce_variations_input_changedtriggered after changing any input fields of the variation. This event is triggered after adding the variation-needs-update class and enabling the "Save changes" button (removing the disabled attribute)woocommerce_variations_defaults_changedtriggered after changing the select "Default Form Values"
META BOXES PRODUCT
woocommerce-product-type-changetriggered when the select "Product Type" changeswoocommerce_added_attributetriggered after adding an attribute row via the "Add" buttonreloadtriggered after reloading the variations panel
SETTINGS
updateMoveButtonstriggered after sorting payment methods or shipping methods
USAGE
Use the admin_enqueue_scripts hook to queue a .js file to run on all admin pages.
In my example I used get_stylesheet_directory_uri() to get the url of the child theme. To get the URI of the root theme you should use get_template_directory_uri().
// queue the "admin-scripts.js" script for all admin pages
add_action( 'admin_enqueue_scripts', 'add_admin_scripts' );
function add_admin_scripts() {
wp_enqueue_script(
'custom_admin_script',
get_stylesheet_directory_uri() . '/js/admin/admin-scripts.js',
array('jquery'),
'1.0',
true
);
}
Then you will need to create an admin-scripts.js file and upload it to the directory: /themes/child-theme/js/admin/admin-scripts.js.
jQuery(function($){
// triggered when the product type changes
$('body').on('woocommerce-product-type-change',function(){
// run code
});
// triggered when the quantity of the order item line changes
$('body').on('quantity_changed',function(){
// run code
});
// ...
});
更多推荐
所有评论(0)