Skip to content

Instantly share code, notes, and snippets.

@wpmudev-sls
Last active February 19, 2018 17:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wpmudev-sls/7b2893a8eb02a9e15b95bd823eb94351 to your computer and use it in GitHub Desktop.
Save wpmudev-sls/7b2893a8eb02a9e15b95bd823eb94351 to your computer and use it in GitHub Desktop.
Display additional fields in app_my_appointments shortcode
<?php
/**
* Plugin Name: Appointment display additional fields
* Plugin URI: https://premium.wpmudev.org/
* Description: Display additional fields in app_my_appointments shortcode
* Author: Ariful Islam @ WPMUDEV
* Author URI: https://premium.wpmudev.org/profile/itsarifulislam
* License: GPLv2 or later
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'AppoinementDisplayAdditionalFields' ) ) {
class AppoinementDisplayAdditionalFields {
private static $_instance = null;
public static function get_instance() {
if ( is_null( self::$_instance ) ) {
self::$_instance = new AppoinementDisplayAdditionalFields();
}
return self::$_instance;
}
private function __construct() {
if ( !function_exists('appointments_get_app_additional_fields') ) return;
// Add Additional Column after date column
add_filter('app_my_appointments_column_name', array( $this, 'app_my_appointments_column_name' ), 10, 1);
// Add Additional Column Value after date column
add_filter('app-shortcode-my_appointments-after_date', array( $this, 'app_shortcode_my_appointments_after_date' ), 10, 2);
}
public function app_my_appointments_column_name( $rows ) {
// Create Array of old row headings
$rows = array_map( function($row) {
return $row . '</th>';
}, array_filter( explode( '</th>', $rows )));
// Move "Status" row from position 3 to 4
$rows[4] = $rows[3];
// Assign New row on position 3 before "Status" row
$rows[3] = '<th class="my-appointments-custom-field">'. __( 'My Field Title', 'appointments' ).'</th>'; // Change the "My Field Title" as you need.
// Return all the rows as string including new rows.
return implode('', $rows);
}
public function app_shortcode_my_appointments_after_date( $row, $r ) {
global $appointments;
// Get the additional fields as array
$additional_fields = appointments_get_app_additional_fields( $r->ID );
// Check the additional field is exist and generate the row
if ( $additional_fields && isset($additional_fields['cufield1']) ) { // change the "cufield1" to your field name, make sure all are lower case and no space.
$row = '<td>'. $additional_fields['cufield1'] .'</td>'; // change the "cufield1" to your field name, make sure all are lower case and no space.
}
// Return the row, which will appear after date
return $row;
}
}
function render_appoinement_display_additional_fields(){
$GLOBALS['AppoinementDisplayAdditionalFields'] = AppoinementDisplayAdditionalFields::get_instance();
}
add_action( 'plugins_loaded', 'render_appoinement_display_additional_fields' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment