Conditional view for the Additional Fields

Please advise how to show Additional Fileds if only a certain service is selected. Please let me know which plugin's core files I need to edit or is it possible to achieve with mu-plugin

  • Lindeni Mahlalela

    Hello Kriss

    I hope you are doing great today. Thank you for contacting us with regards to your questions.

    I have looked into any possibilities to achieve this and it seems we can achieve this entirely with an mu plugin. You can use the filter:

    app_additional_fields

    Which gives you the HTML of the all the fields and you can append anything to it in the form of HTML like so:

    add_filter('app_additional_fields', array( $this, 'app_add_additional_fields' ), 10, 1 );
    function app_add_additional_fields( $fields_html ) {
    	$additional = 'Your Additional Fields Here in the form of HTML ';
    	return  $fields_html . $additional;
    }

    The downside with this is that it will just add the fields without considering any conditions. So, to make this conditional, you should use some JavaScript/jQuery to detect a change in the Services drop down box, if there is a change and the newly selected item is the service you need for these fields then append the field to a specific element in the html. You can any new element using the above hook or append to any existing one.

    I have prepared a template mu plugin which you can expand to achieve anything you want to achieve. If you upload it as it is it should be able to add 2 fields to the the form if the first service is selected. Please find the attached zip file, you can upload it as a regular WordPress plugin on your dashboard by going to "Plugins > Add New" and choose to upload, or you can download it, unzip/extract then upload the .php file to your website in the location:

    wp-content/mu-plugins/app-additional-fields.php

    Please note that this is just a template and additional functionality is still required, but as it is it should be enough to add any fields to the form but you still need to validate and capture the data submitted through the form.

    I hope this helps. Please let us know if you need any additional help, we are always happy to help.

    Have a nice day.
    Mahlamusa

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.