Reputation: 11
I try to use remove_action to remove actions from woocommerce, but can't figure out how to do it.
First I try this:
global $wc_admin_profile;
remove_action( 'show_user_profile', array( $wc_admin_profile, 'add_customer_meta_fields' ) );
remove_action( 'edit_user_profile', array( $wc_admin_profile, 'add_customer_meta_fields' ) );
and I also try this:
add_action( 'admin_init', 'wpdev_170663_remove_parent_theme_stuff', 0 );
function wpdev_170663_remove_parent_theme_stuff() {
global $wc_admin_profile;
remove_action( 'show_user_profile', array( $wc_admin_profile, 'add_customer_meta_fields' ) );
remove_action( 'edit_user_profile', array( $wc_admin_profile, 'add_customer_meta_fields' ) );
}
but they don't work.
/**
* WC_Admin_Profile Class
*/
class WC_Admin_Profile {
/**
* Hook in tabs.
*/
public function __construct() {
add_action( 'show_user_profile', array( $this, 'add_customer_meta_fields' ) );
add_action( 'edit_user_profile', array( $this, 'add_customer_meta_fields' ) );
add_action( 'personal_options_update', array( $this, 'save_customer_meta_fields' ) );
add_action( 'edit_user_profile_update', array( $this, 'save_customer_meta_fields' ) );
add_action( 'show_user_profile', array( $this, 'add_api_key_field' ) );
add_action( 'edit_user_profile', array( $this, 'add_api_key_field' ) );
add_action( 'personal_options_update', array( $this, 'generate_api_key' ) );
add_action( 'edit_user_profile_update', array( $this, 'generate_api_key' ) );
}
Upvotes: 1
Views: 765
Reputation: 493
Sorry for doing a bit of necromancy on this, but I found a much better solution is to use the filter woocommerce_customer_meta_fields
.
Apply it like so:
add_filter('woocommerce_customer_meta_fields', function($fields) {
return [];
});
By returning an empty array inside this filter, this will cause the foreach loop in WC_Admin_Profile::add_customer_meta_fields
to terminate and thus prevent any output.
You can verify this by examining how the filter is applied and processed in the WC_Admin_Profile
class in woocommerce at /woocommerce/includes/admin/class-wc-admin-profile.php
.
Upvotes: 3
Reputation: 1060
You can remove these actions by overriding the WC_Admin_Profile Woocommerce core class.
You can do that by creating an new plugin(creating new php file) and place it inside mu-plugins.
The plugin will contain the definition of the WC_Admin_Profile
class WC_Admin_Profile {
}
return new WC_Admin_Profile();
Now you are free to define you own code inside the newly created class.
We alle know that plugins inside mu-plugins directories execute before any other plugins. So don't try to solve it by placing code inside functions.php inside your active theme directory.
Check this scheme Code execution order scheme
I have faced the same problem and I could solve it by doing that. This solution works 100% because in the class-wc-admin-profile.php
which placed in /wp-content/plugins/woocommerce/includes/admin
you have a check which verify is the class already is defined or not.
if ( ! class_exists( 'WC_Admin_Profile' ) ) :
So because you have already defined your own class, it will never run the class from the Woocommerce core.
I hope it helps :)
Upvotes: 0
Reputation: 2070
If no solution applied then try
remove_all_actions( $tag, $priority );
It will remove actions
Upvotes: 0