Black Friday Sale

30% off Coupon Affiliates PRO with code

Ends in 01Days 00Hrs 35Min 00Sec
Get 30% off

How can we help?

Search the documentation or ask the AI agent anything about the plugin.

Disable the “Custom Commission Per Coupon, Product and User” features for certain admins (Function)

Updated

By default the options to show custom commission settings, and other coupon affiliate settings, per coupon, product, user or user role is available to all administrator users.

If you want to hide these settings/features for user except a certain role or user ID, you can do this by using “remove_action” and “remove filter”, like the following:

/**
 * Unhook WCUsage per commission functions for non-administrators.
 */
function unhook_wcusage_per_commission_functions() {
	if ( current_user_can( 'administrator' ) ) {
		return;
	}

	// Unhook from user profile
	remove_action( 'show_user_profile', 'wcusage_profile_fields' );
	remove_action( 'edit_user_profile', 'wcusage_profile_fields' );
	remove_action( 'personal_options_update', 'wcusage_save_profile_fields' );
	remove_action( 'edit_user_profile_update', 'wcusage_save_profile_fields' );

	// Unhook from WooCommerce product data
	remove_filter( 'woocommerce_product_data_tabs', 'add_wcusage_product_data_tab', 99 );
	remove_action( 'woocommerce_product_data_panels', 'add_wcusage_product_data_fields' );

	// Unhook from WooCommerce coupon data
	remove_filter( 'woocommerce_coupon_data_tabs', 'add_wcusage_coupon_data_tab', 99 );
	remove_action( 'woocommerce_coupon_data_panels', 'add_wcusage_coupon_data_fields', 1 );
	remove_action( 'woocommerce_coupon_options_save', 'wcusage_save_coupon_settings' );
}
add_action( 'init', 'unhook_wcusage_per_commission_functions', 100 );

The if ( current_user_can( ‘administrator’ ) ) check at the start of the function means that it will not apply the unhooks to any users with the role “administrator”, so they will still see the options. You can customise this as needed.

The code may not be 100% complete or tested properly. Please ensure to do your own testing and create website backups before using custom code.

Was this article helpful?