Custom field for Vendor Store Settings

We're shifting our Forum based support to a more dedicated support system!

We'll be closing our Forum support from 10th June, 2020 and move to Email Support assistance.

  • If you are a WCFM premium add-ons user, contact us- here
  • Want to know more before buying our add-ons? Send Pre sale queries- here
  • If you are a WCFM free user, please open a support ticket at WordPress.org
  • For WCFM App related queries, reach us- here
From now the forum will be read-only!

Multi Vendor Marketplace Plugin | WCFM Marketplace Forums WC Vendors Custom field for Vendor Store Settings

Viewing 1 reply thread
  • Author
    Posts
    • #112251
      jaliascv
      Participant

      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..

    • #112390

      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.

Viewing 1 reply thread
  • You must be logged in to reply to this topic.