• Resolved Evolutionsic

    (@evolutionsic)


    I have a copy of a table which i need to duplicate but instead of having hours i need rates. All the styling is already included in my theme i’ve tried changing all the business_hours to business_rates in new files and my website just keeps throwing up errors? I understand because it just needs to hold a number it doesn’t require the jquery anymore. I could make 40 fields and display the data using shortcodes in a widget table but that would drive me nuts

    Table Example

    <table>
      <tr>
        <th>Business Rates</th>
        <th>Incall</th>
        <th>Outcall</th>
      </tr>
      <tr>
        <td></td>
        <td>£15</td>
        <td>£30</td>
      </tr>
      <tr>
        <td></td>
        <td>£30</td>
        <td>£70</td>
      </tr>
      <tr>
        <td></td>
        <td>£</td>
        <td>£</td>
      </tr>
      <tr>
        <td></td>
        <td>£</td>
        <td>£</td>
      </tr>
      <tr>
        <td></td>
        <td>£</td>
        <td>£</td>
      </tr>
      <tr>
        <td></td>
        <td>£</td>
        <td>£</td>
      </tr>
    </table>

    This the form-fields template

    <?php
    /**
     *
     */
    
    global $wp_locale;
    
    if ( is_admin() ) {
    	global $field;
    }
    
    ?>
    
    <table>
    	<tr>
    		<th width="40%">&nbsp;</th>
    		<th align="left"><?php _e( 'Open', 'listify' ); ?></th>
    		<th align="left"><?php _e( 'Close', 'listify' ); ?></th>
    	</tr>
    
    	<?php foreach ( $days as $key => $i ) : ?>
    		<tr>
    			<td align="left"><?php echo $wp_locale->get_weekday( $i ); ?></td>
    			<td align="left" class="business-hour"><input type="text" class="timepicker" name="job_hours[<?php echo $i;
    			?>][start]" value="<?php echo isset( $field[ 'value' ][ $i ] ) && isset( $field[ 'value' ][ $i ][ 'start' ] ) ? $field[ 'value' ][ $i ][ 'start' ] : ''; ?>" class="regular-text" /></td>
    			<td align="left" class="business-hour"><input type="text" class="timepicker" name="job_hours[<?php echo $i;
    			?>][end]" value="<?php echo isset( $field[ 'value' ][ $i ] ) && isset( $field[ 'value' ][ $i ][ 'end' ] )
    			?$field[ 'value' ][ $i ][ 'end' ] : ''; ?>" class="regular-text" /></td>
    		</tr>
    	<?php endforeach; ?>
    </table>

    and heres the function for adding it to front end, back end, and making it appear in wp job manager field editor

    <?php
    
    class Listify_WP_Job_Manager_Business_Hours extends Listify_Integration {
    
    	public function __construct() {
    		$this->includes = array();
    		$this->integration = 'wp-job-manager';
    
    		parent::__construct();
    	}
    
    	public function setup_actions() {
    		add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
    
    		// save [front, back]
    		add_action( 'job_manager_update_job_data', array( $this, 'job_manager_update_job_data' ), 10, 2 );
    		add_action( 'job_manager_save_job_listing', array( $this, 'job_manager_update_job_data' ), 10, 2 );
    
    		// add to frontend
    		add_filter( 'submit_job_form_fields', array( $this, 'submit_job_form_fields' ) );
    	
    		// custom input
    		add_action( 'job_manager_input_business_hours', array( $this, 'job_manager_input_business_hours' ), 10, 2 );
    		
    		// get current value
    		add_filter( 'submit_job_form_fields_get_job_data', array( $this, 'get_job_data' ), 10, 2 );
    
    		// output in admin
    		add_action( 'listify_writepanels_business_hours', array( $this, 'output_admin' ) );
    	}
    
    	public function admin_enqueue_scripts() {
    		global $pagenow;
    
    		if ( ! ( in_array( $pagenow, array( 'post-new.php', 'post.php'  )) && get_post_type() == 'job_listing' ) ) {
    			return;
    		}
    
    		wp_enqueue_script( 'timepicker', listify_Integration::get_url() . 'js/vendor/jquery.timepicker.min.js' );
    		wp_enqueue_style( 'timepicker', get_template_directory_uri() . '/css/vendor/jquery.timepicker.css' );
    	}
    
    	public function submit_job_form_fields( $fields ) {
    		$fields[ 'job' ][ 'job_hours' ] = array(
    			'label'       => __( 'Hours of Operation', 'listify' ),
    			'type'        => 'business-hours',
    			'required'    => false,
    			'placeholder' => '',
    			'priority'    => 4.9,
    			'default'     => ''
    		);
    
    		return $fields;
    	}
    
    	public function job_manager_update_job_data( $job_id, $values ) {
    		if ( ! isset( $_POST[ 'job_hours' ] ) ) {
    			return;
    		}
    
    		update_post_meta( $job_id, '_job_hours', stripslashes_deep( $_POST[ 'job_hours' ] ) );
    	}
    
    	public function get_job_data( $fields, $job ) {
    		$hours = get_post_meta( $job->ID, '_job_hours', true );
    
    		if ( ! $hours ) {
    			return $fields;
    		}
    
    		$fields[ 'job' ][ 'job_hours' ][ 'value' ] = $hours;
    		
    		return $fields;
    	}
    
    	public function job_manager_input_business_hours( $key, $field ) {
    		global $wp_locale, $post, $thepostid;
    
    		$thepostid = $post->ID;
    	?>
    
    	<div class="form-field" style="position: relative;">
    
    		<?php if ( ! is_admin() ) : ?>
    		<label for="<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $field['label'] ) ; ?>:</label>
    		<?php endif; ?>
    
    		<?php
    			global $field;
    
    			if ( empty( $field[ 'value' ] ) ) {
    				$field[ 'value' ] = get_post_meta( $thepostid, '_job_hours', true );
    			}
    
    			get_job_manager_template( 'form-fields/business-hours-field.php' );
    		?>
    
    		<script>
    			(function($) {
    				$( '.timepicker' ).timepicker({
    					timeFormat: '<?php echo str_replace( '\\', '\\\\', get_option( 'time_format' ) ); ?>',
    					noneOption: {
    						label: '<?php _e( 'Closed', 'listify' ); ?>',
    						value: '<?php _e( 'Closed', 'listify' ); ?>' 
    					}
    				});
    			})(jQuery);
    		</script>
    
    	</div>
    
    	<?php
    	}
    
    	public function output_admin() {
    		do_action( 'job_manager_input_business_hours', '_job_hours', array(
    			'label' => __( 'Hours of Operation', 'listify' ),
    			'type' => 'business_hours',
    			'placeholder' => '',
    			'priority' => 99
    		) );
    	}
    }
    
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Changing this to make a rates table?’ is closed to new replies.