wcfm-santa

We've turned 4! Celebrate with us and take away upto 30% off on WCFM Addons.

Claim Offer
03Day 19Hr 16Min 35Sec
wcfm-santa

Custom field for vendor 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!

Viewing 5 reply threads
  • Author
    Posts
    • #66015
      matthias.koch
      Participant

      Hello,

      I am not sure whether there is a bug or I missed something in my attempt to add a custom settings field to the vendor settings page.
      I used this hook
      add_filter('wcfm_marketplace_settings_fields_general', array($this, 'add_allow_invoice'), 20);
      to add a checkbox like this:

      	function add_allow_invoice($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();
      		$allow_invoice = isset( $vendor_data['allow_invoice'] ) ? esc_attr( $vendor_data['allow_invoice'] ) : 'no';
      		$settings_fields_general['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 $settings_fields_general;
      	}

      So far, so good, the checkbox appears and I can check it. When I check it and save it, the value gets stored.

      However, if I uncheck the previously checked box and save the form, the value does not get set to “no”, because the “wcfm_settings_form” in “data” in line 147 in the file \wp-content\plugins\wc-frontend-manager\assets\js\vendors\wcfm-script-vendors-manage.js does not contain the checkbox at all. During runtime, it is only included in the serialized form when I checked it.
      Without having digged deeper so far, I assume, for fields added via the filter, there is an issue with checkboxes once they are unchecked.
      Could you please have a look at the issue? I would be very happy if you could help me. 🙂

      Thank you and best regards
      Matthias

    • #66261
      WCFM Forum
      Keymaster

      HI,

      Please use this code save this field separately –

      add_action( 'wcfm_vendor_settings_update', function( $vendor_id, $wcfm_settings_form ) {
      	global $WCFM, $WCFMmp;
      	if( isset( $wcfm_settings_form['allow_invoice'] ) ) {
      	    update_user_meta( $vendor_id, 'allow_invoice',  'yes' );
      	} else {
                  update_user_meta( $vendor_id, 'allow_invoice',  'yes' );
              }
      }, 500, 2 );

      and directly read from meta –

      get_user_meta( $vendor_id, 'allow_invoice', true );

      Thank You

    • #66361
      matthias.koch
      Participant

      Thank you for your reply! This brings me already one step forward.

      Sadly, I have one more issue:

      	function save_custom_vendor_settings($vendor_id, $wcfm_settings_form) {
      		global $WCFM, $WCFMmp;
      		if( isset( $wcfm_settings_form['allow_invoice'] ) ) {
      			$a = $wcfm_settings_form['allow_invoice']; //ISSUE: Always "yes"
      			update_user_meta( $vendor_id, 'allow_invoice',  $wcfm_settings_form['allow_invoice'] );
      		} else {
      			update_user_meta( $vendor_id, 'allow_invoice',  'no' );
      		}
      	}

      In the line where (for testing only) I set the $a variable, I notice that the value of $wcfm_settings_form['allow_invoice'] is always “yes”, even though I have the checkbox unchecked.
      Did I miss something else?

      Thank you again for your support!
      Regards
      Matthias

    • #66852
      WCFM Forum
      Keymaster

      HI,

      Sorry, my code was wrong. Here is corrected one –

      add_action( 'wcfm_vendor_settings_update', function( $vendor_id, $wcfm_settings_form ) {
      	global $WCFM, $WCFMmp;
      	if( isset( $wcfm_settings_form['allow_invoice'] ) ) {
      	    update_user_meta( $vendor_id, 'allow_invoice',  'yes' );
      	} else {
                  update_user_meta( $vendor_id, 'allow_invoice',  'no' );
              }
      }, 500, 2 );

      Thank You

    • #67181
      matthias.koch
      Participant

      This works perfectly now, thank you very much!

    • #67415
      WCFM Forum
      Keymaster

      Glad to here, you are welcome 🙂

Viewing 5 reply threads
  • The topic ‘Custom field for vendor settings’ is closed to new replies.