0
votes

I've searched all over this site and others for instructions on how to remove an action from a parent theme and nothing seems to work. I'm trying to remove the 'add_action' line via my child theme functions file:

class Quickmart_Woocommerce{
  public function __construct(){
  add_action( 'wp_enqueue_scripts', array( $this, 'loadThemeStyles' ), 20 );
}

And here is the function the add_action is referencing

public function loadThemeStyles() {
  wp_enqueue_style( 'quickmart-woocommerce', $path , 'quickmart-woocommerce-front' , QUICKMART_THEME_VERSION, 'all' );
}

I've tried using the following, but it's not working

global $Quickmart_Woocommerce;
remove_action( 'wp_enqueue_scripts', array( $Quickmart_Woocommerce, 'loadThemeStyles' ) );

I'm really stumped.

3

3 Answers

0
votes

You can simplify this by hooking your own function into the wp_enqueue_style action at a later priority and removing the style. The priority of 21 makes sure your code runs after the initial enqueue, which has a priority of 20.

function my_theme_remove_styles(){
    wp_dequeue_style( 'quickmart-woocommerce');
}

add_action('wp_enqueue_style', 'my_theme_remove_styles', 21);
0
votes

You need dequeue the scripts, because the hook "wp_enqueue_scripts" is needed by others resources.

Remove an enqueued script.

To be dequeued, the script must have been enqueued. Attempting to dequeue a script before the script is enqueued will have no effect.

so you need add this to your function.php

function wpdocs_dequeue_script() {
   wp_dequeue_script( 'quickmart-woocommerce' );
}
add_action( 'wp_print_scripts', 'wpdocs_dequeue_script', 100 );
-1
votes

Found the answer in case anybody else is interested:

add_action( 'wp_print_styles', 'my_deregister_styles', 100 );

function my_deregister_styles() {
    wp_deregister_style( 'quickmart-woocommerce' );
}

Source: http://justintadlock.com/archives/2009/08/06/how-to-disable-scripts-and-styles