WC_Settings_API::generate_settings_html()publicWC 1.0.0

Generate Settings HTML.

Generate the HTML for the fields on the "settings" screen.

{} It's a method of the class: WC_Settings_API{}

Hooks from the method

Return

String. the html for the settings

Usage

$WC_Settings_API = new WC_Settings_API();
$WC_Settings_API->generate_settings_html( $form_fields, $echo );
$form_fields(array)
(default: array()) Array of form fields.
Default: array()
$echo(true|false)
Echo or return.
Default: true

Changelog

Since 1.0.0 Introduced.

Code of WC_Settings_API::generate_settings_html() WC 6.8.2

public function generate_settings_html( $form_fields = array(), $echo = true ) {
	if ( empty( $form_fields ) ) {
		$form_fields = $this->get_form_fields();
	}

	$html = '';
	foreach ( $form_fields as $k => $v ) {
		$type = $this->get_field_type( $v );

		if ( method_exists( $this, 'generate_' . $type . '_html' ) ) {
			$html .= $this->{'generate_' . $type . '_html'}( $k, $v );
		} elseif ( has_filter( 'woocommerce_generate_' . $type . '_html' ) ) {
			/**
			 * Allow the generation of custom field types on the settings screen.
			 *
			 * The dynamic portion of the hook name refers to the slug of the custom field type.
			 * For instance, to introduce a new field type `fancy_lazy_dropdown` you would use
			 * the hook `woocommerce_generate_fancy_lazy_dropdown_html`.
			 *
			 * @since 6.5.0
			 *
			 * @param string $field_html The markup of the field being generated (initiated as an empty string).
			 * @param string $key The key of the field.
			 * @param array  $data The attributes of the field as an associative array.
			 * @param object $wc_settings The current WC_Settings_API object.
			 */
			$html .= apply_filters( 'woocommerce_generate_' . $type . '_html', '', $k, $v, $this );
		} else {
			$html .= $this->generate_text_html( $k, $v );
		}
	}

	if ( $echo ) {
		echo $html; // WPCS: XSS ok.
	} else {
		return $html;
	}
}