How to dequeue or deregister specific woocoomerce script in wordpress admin panel - wordpress

I need to remove Woocommerce script: wc-admin-order-meta-boxes-js (woocommerce/assets/js/admin/meta-boxes-order.min.js) from the edit-order page or all admin pages in woocommerce. I tried everything but nothing works. Can anyone help me? Thanks.
For example, I tried this:
add_action( 'admin_print_script', 'remove_admin_scripts', 1 );
function remove_admin_scripts() {
// Dequeue
wp_dequeue_script( 'wc-admin-order-meta-boxes-js' );
// Deregister
wp_deregister_script( 'wc-admin-order-meta-boxes-js' );
}

You are calling the wrong name of the script. You can just dequeue as it is enqueued, but with a higher priority.
add_action( 'admin_enqueue_scripts', 'remove_admin_scripts', 99 );
function remove_admin_scripts() {
// Dequeue.
wp_dequeue_script( 'wc-admin-order-meta-boxes' );
// Deregister.
wp_deregister_script( 'wc-admin-order-meta-boxes' );
}
This is tested and works.

Related

wp_dequeue_script not work | WordPress 6.1.1

I want to remove custom js and css of core wordpress.
I followed the construction on wordpress.org
function wpdocs_dequeue_script( ) {
wp_dequeue_script( 'jquery-ui-core' );
}
add_action( 'wp_print_scripts', 'wp_dequeue_script', 100 );
Unfortunately, this not work in my case.
I installed WordPress 6.1.1. Is there any changes?
you need to call your function in the hook:
function wpdocs_dequeue_script( ) {
wp_dequeue_script( 'jquery-ui-core' );
}
add_action( 'wp_print_scripts', 'wpdocs_dequeue_script', 100 );

Dequeue scripts and styles on login page

I am trying to find a way to dequeue styles and scripts on the "login, password reset and register " default wp pages.
I understand there is 'login_enqueue_scripts' but no such thing as login_dequeue_scripts.
Whats your approach ? Ive tried something like this:
add_filter('body_class', function($classes) {
if (in_array('login', $classes)) {
wp_dequeue_style( 'list-css' );
wp_dequeue_style( 'blog-css' );
wp_dequeue_style( 'dir-css' );
wp_dequeue_style( 'author-css' );
}
return $classes;
});```
You could just use the wp_dequeue_script/style function for the login_enqueue_script action. Like so:
function custom_login_page() {
wp_dequeue_style( 'list-css');
}
add_action( 'login_enqueue_scripts', 'custom_login_page' );
The action of 'login_enqueue_scripts' is what happens when the other scripts/styles are loaded on that page. You can create a custom function to run when that happens, which is what you want.
However, rather than dequeueing, why not just write some of your own CSS for the elements on the page, then enqueue whatever that custom CSS?
function custom_login_css() {
wp_enqueue_style( 'custom-login-styles', get_stylesheet_directory_uri() . '/custom-login.css' );
}
add_action( 'login_enqueue_scripts', 'custom_login_css' );
Here's a good reference for the different elements you can customize with CSS on the WP login page.

Wordpress Dequeue Script not working (with jquery)

I am trying to dequeue the following plugin scripts:
function afg_enqueue_cbox_scripts() {
wp_enqueue_script('jquery');
wp_enqueue_script('afg_colorbox_script', BASE_URL . "/colorbox/jquery.colorbox-min.js" , array('jquery'));
wp_enqueue_script('afg_colorbox_js', BASE_URL . "/colorbox/mycolorbox.js" , array('jquery'));
}
I tried adding this in functions.php:
add_filter('wp_print_styles', 'remove_mycred', 100);
function remove_mycred() {
wp_dequeue_script( 'afg_colorbox_script' );
wp_dequeue_script( 'afg_colorbox_js' );
}
But it does not work at all - both scripts are still there.
There are other scripts that I have no problems dequeuing - just not those.
I suspect jquery has something to do with my problems?
thanks!
Blaise
You have two problems here, you should use wp_enqueue_scripts hook to hook your function to. Secondly, you will need to go and look at the priority which the author used to enqueue these scripts, and then give your action hook a lower (higher number) priority. Your code should look something like this
function remove_mycred() {
wp_deregister_script( 'afg_colorbox_script' );
wp_dequeue_script( 'afg_colorbox_script' );
wp_deregister_script( 'afg_colorbox_js' );
wp_dequeue_script( 'afg_colorbox_js' );
}
add_action( 'wp_enqueue_scripts', remove_mycred, 9999 );

Trying to deregister a WooCommerce script without success

I'm trying to deregister a WooCommerce script called 'add-to-cart-variation' found in the following path :theme-folder/woocommerce/assets/js/frontend.
The idea is to by-pass the default script which controls the 'add-to-cart' button for variable products. By default, the 'add-to-cart' button is visible only when the user/customer has selected the variations available to them in the product page, I'm looking to have this button visible at all times.
I added the code below to the functions.php and added add-to-cart-variation.min.js to the child-theme-folder/woocommerce/assets/js/frontend.
Unfortunately I don't see any change, any suggestions for me?
function register_woo_radio_button_scripts () {
wp_deregister_script('add-to-cart-variation');
wp_dequeue_script('add-to-cart-variation');
wp_register_script( 'add-to-cart-variation', plugins_url( get_stylesheet_directory_uri().'woocommerce/assests/js/frontend/add-to-cart-variation.min.js', __FILE__ ), array( 'jquery'), false, true );
wp_enqueue_script('add-to-cart-variation');
}
add_action( 'wp_enqueue_script', 'register_woo_radio_button_scripts' );
This works fine for me:
function wc_deregister_javascript()
{
wp_deregister_script( 'wc-add-to-cart-variation' );
}
add_action( 'wp_print_scripts', 'wc_deregister_javascript', 100 );

Deregister scripts on unnecessary pages in WP

I have installed WP Pokks plugin. I using in on some of pages and need to deregister its styles and scripts on other pages.
I found some code in plugin which registers scripts:
### Function: Enqueue Polls JavaScripts/CSS
add_action('wp_enqueue_scripts', 'poll_scripts');
function poll_scripts() {
// code
}
So for deregistering its scripts i am using next code in my functions.php:
add_action( 'wp_enqueue_scripts', 'deregister_polls_scripts_and_styles' );
function deregister_polls_scripts_and_styles() {
if ( is_home() ) {
remove_action( 'wp_enqueue_scripts', 'poll_scripts');
}
}
So it must deregister polls scripts on homepage, but id does not. What i am doing wrong?
You can use like this
add_action( 'wp_print_scripts', 'de_script', 100 );
function de_script() {
wp_dequeue_script( 'jquery' );
wp_deregister_script( 'jquery' );
}

Resources