Hi all,
just a quick sharing.
I wanted to add a custom field for Vendor Settings in WCFM. The field will be a checkbox with a label of "Verified". This field can only be filled by an admin.
The purpose tells is to tell whether this vendor is verified or not and data is stored in `wp_usermeta` table.
Okay, of course, if I use the paid extension for WCFM plugin this feature already included. But come on! I just want to add this simple function without paying any penny :P
Thus I decided to DIM (Do it Myself).
I was lucky that previously other WCFM users did a custom field for Vendor Settings and shared his solution on the WCFM forum. Aha.
So I tested out, in the beginning, it was not working. The working code I included here for your reference. I also added the admin user check to ensure the field is only loaded for admin view :D. This code needed to be in your child theme `functions.php`!
The code first will add the new field to the vendor setting form, then the value "is_verified" that passed from the form will be updated to the vendor user meta value for meta key `is_verified`.
Result:
Reference:
https://wclovers.com/forums/topic/custom-field-for-vendor-settings/
P/s: give me a shout, any questions? don't hesitate to leave your comment! I'll try to help out!
just a quick sharing.
How to add Custom Field for Vendor Settings in WCFM
![]() |
I wanted to add a custom field for Vendor Settings in WCFM. The field will be a checkbox with a label of "Verified". This field can only be filled by an admin.
The purpose tells is to tell whether this vendor is verified or not and data is stored in `wp_usermeta` table.
Okay, of course, if I use the paid extension for WCFM plugin this feature already included. But come on! I just want to add this simple function without paying any penny :P
Thus I decided to DIM (Do it Myself).
I was lucky that previously other WCFM users did a custom field for Vendor Settings and shared his solution on the WCFM forum. Aha.
So I tested out, in the beginning, it was not working. The working code I included here for your reference. I also added the admin user check to ensure the field is only loaded for admin view :D. This code needed to be in your child theme `functions.php`!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function is_site_admin(){ | |
return in_array('administrator', wp_get_current_user()->roles); | |
} | |
if (is_site_admin()) { | |
add_filter('wcfm_marketplace_settings_fields_general', 'add_vendor_verified', 10, 2); | |
add_action( 'wcfm_vendor_settings_update', 'fn_wcfm_vendor_settings_storetype_update', 30, 2); | |
} | |
function add_vendor_verified($settings_fields_general, $vendor_id){ | |
$vendor_data = get_user_meta( $vendor_id, 'wcfmmp_profile_settings', true ); | |
$is_verified = isset( $vendor_data['is_verified'] ) ? esc_attr( $vendor_data['is_verified'] ) : 0; | |
if (isset($settings_fields_general['store_name'])) { | |
$settings_fields_general['is_verified']= array( | |
'label' => __( 'Verified', 'woocommerce' ), | |
'type' => 'checkbox', | |
'priority' => 50, | |
'class' => 'wcfm-checkbox wcfm_ele', | |
'label_class' => 'wcfm_title wcfm_ele', | |
'value' => 1, | |
'dfvalue' => $is_verified, | |
); | |
} | |
return $settings_fields_general; | |
} | |
function fn_wcfm_vendor_settings_storetype_update( $vendor_id, $wcfm_settings_form ) { | |
$wcfm_settings_form_data_new = array(); | |
parse_str($_POST['wcfm_settings_form'],$wcfm_settings_form_data_new); | |
$wcfm_settings_form_data_storetype = array(); | |
if(isset($wcfm_settings_form_data_new['is_verified']) && !empty($wcfm_settings_form_data_new['is_verified'])) { | |
if ($wcfm_settings_form_data_new['is_verified'] == 1){ | |
$wcfm_settings_form_data_storetype['is_verified'] = 1; | |
}else { | |
$wcfm_settings_form_data_storetype['is_verified'] = 0; | |
} | |
} | |
else { | |
$wcfm_settings_form_data_storetype['is_verified'] = 0; | |
} | |
$wcfm_settings_form = array_merge( $wcfm_settings_form, $wcfm_settings_form_data_storetype ); | |
update_user_meta( $vendor_id, 'wcfmmp_profile_settings', $wcfm_settings_form ); | |
} |
Result:
![]() |
The custom field will be showing in Vendor store settings. Only visible to admin user :D |
Reference:
https://wclovers.com/forums/topic/custom-field-for-vendor-settings/
P/s: give me a shout, any questions? don't hesitate to leave your comment! I'll try to help out!
Comments
Post a Comment