Remove action within a class in a parent theme from the child theme

To remove an action or filter, the function/method name and the priority must match with the previously added action/filter. The action you want to remove is added with a priority of 10 (default value) while you are trying to remove the action with priority of 99.

Try this:

remove_action( 'woocommerce_product_options_inventory_product_data', array( 'Electro_WC_Helper', 'product_options_inventory_product_data' ) );
// It is the same that:
// remove_action( 'woocommerce_product_options_inventory_product_data', array( 'Electro_WC_Helper', 'product_options_inventory_product_data' ), 10 );

Also, functions.php file from child theme is loaded before the functions.php file from the parent theme, so, the execution of remove_action() function in the child theme must be deferred using some action hook, because it must wait until the parent theme adds the action we want to remove. admin_head is an action that only happens on admin side and not associated with themes, so it does not triggered on front-end. You should use a proper action, which depends how exactly the parent theme is adding the action event; typically you should use after_setup_theme with a high priority:

add_action( 'after_setup_theme', 'cyb_remove_parent_theme_action', 0 );
function cyb_remove_parent_theme_action() {
    remove_action( 'woocommerce_product_options_inventory_product_data', array( 'Electro_WC_Helper', 'product_options_inventory_product_data' ) );
}

Leave a Comment