cwcfp_user_capability

The cwcfp_user_capability filter lets store administrators determine which user role can access various areas of Conditional Checkout Fields.

By default, the filter returns manage_options, which is reserved for Administrators in WordPress. If you do nothing with this filter, your Conditional Fields will only be able to be viewed, edited, exported by a site administrator.

This filter has the following arguments:

  • $capability: Default is manage_options. To learn more about WordPress capabilities, please click here. WooCommerce also has their own capabilities that you can learn more about here.
  • $function: Refers to what you are allowing the user to do. 
    • view_menu: Allows a user to view the WooCommerce > Conditional Fields menu as well as all of the field information.
    • edit_conditional_fields: Allows a user to edit the conditional fields.
    • edit_default_fields: Allows a user to edit the default fields.
    • export_orders: Allows a user to export orders.

To allow shop managers to use Conditional Checkout Fields, you would need to use the filter like this:

add_filter( 'cwcfp_user_capability', 'conditional_fields_allow_shop_manager', 10, 2 );
function conditional_fields_allow_shop_manager( $capability, $function ){
	return 'manage_woocommerce';
}

To allow shop managers only view Conditional Checkout Fields, you would need to use the filter like this:

add_filter( 'cwcfp_user_capability', 'conditional_fields_allow_shop_manager_view_only', 10, 2 );
function conditional_fields_allow_shop_manager_view_only( $capability, $function ){
	switch( $function ){
		case 'view_menu':
			$capability = 'manage_woocommerce';
			break;
		default:
			$capability = 'manage_options';
			break;
	}
	return $capability;
}

In the example above, shop managers will be able to view all of the conditional fields, default fields, and view each of their settings. They will not be able to export or save changes to the conditional or default fields.

Note: Only WordPress Administrators are allowed to edit the settings on the WooCommerce > Conditional Fields > Settings tab as this data can potentially modify how the site handles sensitive data. However, these settings typically aren't modified often after the initial setup.