Or, embed this snippet using GenerateWP WordPress Plugin.

Download

Clone

breakdowns_meta

class rcrm_breakdowns_Meta {

	public function __construct() {

		if ( is_admin() ) {

			add_action( 'breakdowns_add_form_fields',  array( $this, 'create_screen_fields'), 10, 1 );
			add_action( 'breakdowns_edit_form_fields', array( $this, 'edit_screen_fields' ),  10, 2 );

			add_action( 'created_breakdowns', array( $this, 'save_data' ), 10, 1 );
			add_action( 'edited_breakdowns',  array( $this, 'save_data' ), 10, 1 );

		}

	}

	public function create_screen_fields( $taxonomy ) {

		// Set default values.
		$rcrm_meta_price = 'Nous contacter';
		$rcrm_meta_icon = '';

		// Form fields.
		echo '<div class="form-field term-rcrm_meta_price-wrap">';
		echo '	<label for="rcrm_meta_price">' . __( 'Price', 'computer-repair' ) . '</label>';
		echo '	<input type="text" id="rcrm_meta_price" name="rcrm_meta_price" placeholder="' . esc_attr__( 'Price', 'computer-repair' ) . '" value="' . esc_attr( $rcrm_meta_price ) . '">';
		echo '</div>';

		echo '<div class="form-field term-rcrm_meta_icon-wrap">';
		echo '	<label for="rcrm_meta_icon">' . __( 'Icon', 'computer-repair' ) . '</label>';
		echo '	<input type="text" id="rcrm_meta_icon" name="rcrm_meta_icon" placeholder="' . esc_attr__( 'Icon code', 'computer-repair' ) . '" value="' . esc_attr( $rcrm_meta_icon ) . '">';
		echo '</div>';

	}

	public function edit_screen_fields( $term, $taxonomy ) {

		// Retrieve an existing value from the database.
		$rcrm_meta_price = get_term_meta( $term->term_id, 'rcrm_meta_price', true );
		$rcrm_meta_icon = get_term_meta( $term->term_id, 'rcrm_meta_icon', true );

		// Set default values.
		if( empty( $rcrm_meta_price ) ) $rcrm_meta_price = 'Nous contacter';
		if( empty( $rcrm_meta_icon ) ) $rcrm_meta_icon = '';

		// Form fields.
		echo '<tr class="form-field term-rcrm_meta_price-wrap">';
		echo '<th scope="row">';
		echo '	<label for="rcrm_meta_price">' . __( 'Price', 'computer-repair' ) . '</label>';
		echo '</th>';
		echo '<td>';
		echo '	<input type="text" id="rcrm_meta_price" name="rcrm_meta_price" placeholder="' . esc_attr__( 'Price', 'computer-repair' ) . '" value="' . esc_attr( $rcrm_meta_price ) . '">';
		echo '</td>';
		echo '</tr>';

		echo '<tr class="form-field term-rcrm_meta_icon-wrap">';
		echo '<th scope="row">';
		echo '	<label for="rcrm_meta_icon">' . __( 'Icon', 'computer-repair' ) . '</label>';
		echo '</th>';
		echo '<td>';
		echo '	<input type="text" id="rcrm_meta_icon" name="rcrm_meta_icon" placeholder="' . esc_attr__( 'Icon code', 'computer-repair' ) . '" value="' . esc_attr( $rcrm_meta_icon ) . '">';
		echo '</td>';
		echo '</tr>';

	}

	public function save_data( $term_id ) {

		// Sanitize user input.
		$rcrm_new_meta_price = isset( $_POST[ 'rcrm_meta_price' ] ) ? sanitize_text_field( $_POST[ 'rcrm_meta_price' ] ) : '';
		$rcrm_new_meta_icon = isset( $_POST[ 'rcrm_meta_icon' ] ) ? sanitize_text_field( $_POST[ 'rcrm_meta_icon' ] ) : '';

		// Update the meta field in the database.
		update_term_meta( $term_id, 'rcrm_meta_price', $rcrm_new_meta_price );
		update_term_meta( $term_id, 'rcrm_meta_icon', $rcrm_new_meta_icon );

	}

}

new rcrm_breakdowns_Meta;