0

There's a class in parent's theme includes folder which adds action i want to remove in the child theme functions.php or in the plugin

class A {
   public function __construct() {
      ...
      add_action( 'woocommerce_before_customer_login_form', array( $this, 'before_customer_login_form' ) );
      ...
   }


    public function before_customer_login_form() {
        echo ( 'yes' !== get_option( 'woocommerce_enable_myaccount_registration' ) ) ? '<div id="customer_login" class="woocommerce-content-box full-width">' : '';
    }
}

functions.php code inspired by solution from here

function remove_woo_forms_hooks() {
    remove_action('woocommerce_before_customer_login_form', array('A','before_customer_login_form'));
}

add_action( 'after_setup_theme', 'remove_woo_forms_hooks',0);

Though action removal doesn't work. before_customer_login_form action is still fired.

Suspect that the code

remove_action('woocommerce_before_customer_login_form',array('A','before_customer_login_form'));

is not correct.

How to remove the action correctly?

1

1 Answer 1

1

Thanks a lot to Nathan Johnson:

The solution was to use instance of the class the action was defined in. The class was globalized in the theme after instantiation. So the adding the below code to functions.php of a Child Theme worked:

function remove_woo_forms_hooks() {
    global $woo_a;
    remove_action('woocommerce_before_customer_login_form', array($woo_a,'before_customer_login_form'));
}

add_action( 'after_setup_theme', 'remove_woo_forms_hooks',0);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.