<?php
/**
 * Custom template tags for this theme.
 *
 * Eventually, some of the functionality here could be replaced by core features
 *
 * @package Educational Landing Page 
 */

/*-- Custom metafield for product--*/
function educational_landing_page_custom_job_field() {
  	add_meta_box( 'bn_meta', __( 'Educational Landing Page Meta Fields', 'educational-landing-page' ), 'educational_landing_page_meta_technology_callback', 'post', 'normal', 'high' );
}
if (is_admin()){
  	add_action('admin_menu', 'educational_landing_page_custom_job_field');
}

function educational_landing_page_meta_technology_callback( $post ) {
  	wp_nonce_field( basename( __FILE__ ), 'educational_landing_page_technology_meta' );
  	$bn_stored_meta = get_post_meta( $post->ID );
  	$educational_landing_page_rating = get_post_meta( $post->ID, 'educational_landing_page_rating', true );
  	$educational_landing_page_rating1 = get_post_meta( $post->ID, 'educational_landing_page_rating1', true );
  	$educational_landing_page_user = get_post_meta( $post->ID, 'educational_landing_page_user', true );
  	$educational_landing_page_price_sec = get_post_meta( $post->ID, 'educational_landing_page_price_sec', true );
  	$educational_landing_page_price_sec1 = get_post_meta( $post->ID, 'educational_landing_page_price_sec1', true );
  	?>

  	<div id="custom_meta_feilds">
	    <table id="list">
	      	<tbody id="the-list" data-wp-lists="list:meta">
		        <tr id="meta-8">
		          	<td class="left">
		            	<?php esc_html_e( 'Star Rating :', 'educational-landing-page' )?>
		          	</td>
		          	<td class="left">
    					<input type="number" name="educational_landing_page_rating" id="star-rating w-100" value="<?php echo esc_attr($educational_landing_page_rating); ?>"min="0" max="5" />
		          	</td>

		          	<td>
		        </tr>

				<tr id="meta-8">
		          	<td class="left">
		            	<?php esc_html_e( 'Star Rating Count :', 'educational-landing-page' )?>
		          	</td>
		          	<td class="left">
    					<input type="number" name="educational_landing_page_rating1" id="star-rating" value="<?php echo esc_attr($educational_landing_page_rating1); ?>"min="0" max="5" />
		          	</td>
		          	<td>
		        </tr>
	      		<tr id="meta-8">
		          	<td class="left">
		            	<?php esc_html_e( 'User Text :', 'educational-landing-page' )?>
		          	</td>
		          	<td class="left">
		            	<input type="text" name="educational_landing_page_user" id="educational_landing_page_user" value="<?php echo esc_attr($educational_landing_page_user); ?>" />
		          	</td>
		        </tr>
		        <tr id="meta-8">
		          	<td class="left">
		            	<?php esc_html_e( 'Regular price ($) :', 'educational-landing-page' )?>
		          	</td>
		          	<td class="left">
		            	<input type="number" name="educational_landing_page_price_sec" id="educational_landing_page_price_sec" value="<?php echo esc_attr($educational_landing_page_price_sec); ?>" />
		          	</td>
		        </tr>
		        <tr id="meta-8">
		          	<td class="left">
		            	<?php esc_html_e( 'Sale price ($) :', 'educational-landing-page' )?>
		          	</td>
		          	<td class="left">
		            	<input type="number" name="educational_landing_page_price_sec1" id="educational_landing_page_price_sec1" value="<?php echo esc_attr($educational_landing_page_price_sec1); ?>" />
		          	</td>
		        </tr>
	      	</tbody>
	    </table>
  	</div>
  	<?php
}

function educational_landing_page_save( $post_id ) {
  	if (!isset($_POST['educational_landing_page_technology_meta']) || !wp_verify_nonce( strip_tags( wp_unslash( $_POST['educational_landing_page_technology_meta']) ), basename(__FILE__))) {
      	return;
  	}
  	if (!current_user_can('edit_post', $post_id)) {
   		return;
  	}
  	if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
    	return;
  	}
  	if( isset( $_POST[ 'educational_landing_page_rating' ] ) ) {
    	update_post_meta( $post_id, 'educational_landing_page_rating', strip_tags( wp_unslash( $_POST[ 'educational_landing_page_rating' ]) ) );
  	}
  	if( isset( $_POST[ 'educational_landing_page_rating1' ] ) ) {
    	update_post_meta( $post_id, 'educational_landing_page_rating1', strip_tags( wp_unslash( $_POST[ 'educational_landing_page_rating1' ]) ) );
  	}
  	if( isset( $_POST[ 'educational_landing_page_user' ] ) ) {
    	update_post_meta( $post_id, 'educational_landing_page_user', strip_tags( wp_unslash( $_POST[ 'educational_landing_page_user' ]) ) );
  	}
  	if( isset( $_POST[ 'educational_landing_page_price_sec' ] ) ) {
    	update_post_meta( $post_id, 'educational_landing_page_price_sec', strip_tags( wp_unslash( $_POST[ 'educational_landing_page_price_sec' ]) ) );
  	}
  	if( isset( $_POST[ 'educational_landing_page_price_sec1' ] ) ) {
    	update_post_meta( $post_id, 'educational_landing_page_price_sec1', strip_tags( wp_unslash( $_POST[ 'educational_landing_page_price_sec1' ]) ) );
  	}
}
add_action( 'save_post', 'educational_landing_page_save' );