Multi Vendor Marketplace Plugin | WCFM Marketplace › Forums › WC Vendors › Custom field for Vendor Store Settings
Tagged: custom field, vendor
- This topic has 1 reply, 2 voices, and was last updated 4 years, 8 months ago by Sarmistha Chakraborty.
Viewing 1 reply thread
- AuthorPosts
- March 19, 2020 at 2:04 pm #112251jaliascvParticipant
Hi all,
Inquiry: I would like to create a new custom field for vendor in Store Settings which can only be updated admin.
What i have done? : I’ve gone thru in forum and try to apply the same thing however i m stuck whereby the new field is not saved properly, eg only set as “yes” even though the checkbox is unchecked. https://wclovers.com/forums/topic/custom-field-for-vendor-settings/
I’ve applied the following codes in child theme functions.php…
Code snippets:
function add_vendor_verified($settings_fields_general){ $vendor_id = $settings_fields_general['vendor_id']['value']; $vendor_data = get_user_meta( $vendor_id, 'wcfmmp_profile_settings', true ); if( !$vendor_data ) $vendor_data = array(); $on_demand = isset( $vendor_data['on_demand'] ) ? esc_attr( $vendor_data['on_demand'] ) : 'no'; $settings_fields_general['on_demand'] = array( 'label' => __( 'On Demand', 'woocommerce' ), 'type' => 'checkbox', 'priority' => 50, 'class' => 'wcfm-checkbox wcfm_ele', 'label_class' => 'wcfm_title wcfm_ele', 'value' => 'yes', 'dfvalue' => $on_demand, ); return $settings_fields_general; } add_filter('wcfm_marketplace_settings_fields_general', 'add_vendor_on_demand', 20); add_action( 'wcfm_vendor_settings_update', function( $vendor_id, $wcfm_settings_form ) { global $WCFM, $WCFMmp; if( isset( $wcfm_settings_form['on_demand'] ) ) { update_user_meta( $vendor_id, 'on_demand', 'yes' ); } else { update_user_meta( $vendor_id, 'on_demand', 'no' ); } }, 10, 2 );
Please help to advice..
- March 20, 2020 at 6:39 pm #112390Sarmistha ChakrabortyMember
Hello,
Kindly modify your code,
add_filter('wcfm_marketplace_settings_fields_general','wcfm_marketplace_add_custom_field_settings_fields_general',10,2); function wcfm_marketplace_add_custom_field_settings_fields_general($fields, $user_id) { $vendor_data = get_user_meta( $user_id, 'wcfmmp_profile_settings', true ); $allow_invoice = isset( $vendor_data['allow_invoice'] ) ? esc_attr( $vendor_data['allow_invoice'] ) : 'no'; if(isset($fields['store_name'])) { $fields['allow_invoice'] = array( 'label' => __( 'Rechnung erlauben', 'ddwoo' ), 'type' => 'checkbox', 'priority' => 50, 'class' => 'wcfm-checkbox wcfm_ele', 'label_class' => 'wcfm_title wcfm_ele', 'value' => 'yes', 'dfvalue' => $allow_invoice ); } return $fields; } add_action( 'wcfm_wcfmmp_settings_update','fn_wcfm_vendor_settings_storetype_update', 30, 2); add_action( 'wcfm_vendor_settings_update','fn_wcfm_vendor_settings_storetype_update', 30, 2); function fn_wcfm_vendor_settings_storetype_update($user_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['allow_invoice']) && !empty($wcfm_settings_form_data_new['allow_invoice'])) { $wcfm_settings_form_data_storetype['allow_invoice'] = 'yes'; } else { $wcfm_settings_form_data_storetype['allow_invoice'] = 'no'; } $wcfm_settings_form = array_merge( $wcfm_settings_form, $wcfm_settings_form_data_storetype ); update_user_meta( $user_id, 'wcfmmp_profile_settings', $wcfm_settings_form ); }
Thanks.
- AuthorPosts
Viewing 1 reply thread
- You must be logged in to reply to this topic.