Last active
February 21, 2024 21:14
-
-
Save Garconis/720099596f3ba6f086d83864920fca15 to your computer and use it in GitHub Desktop.
Admin Columns Pro | Overwrite an Order column with values from a FooEvents Attendee array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Filter the display value for a column | |
* | |
* @param mixed $value Custom field value | |
* @param int $id Object ID | |
* @param AC_Column $column Column instance | |
*/ | |
function ac_my_custom_field_column_value_example( $value, $id, $column ) { | |
if ( $column instanceof ACP\Column\CustomField ) { | |
// get the meta key of this column | |
$meta_key = $column->get_meta_key(); | |
// if the meta key is the FooEvents Attendee Field one that we want data from | |
if ( 'WooCommerceEventsOrderTickets' == $meta_key ) { | |
// example of replacing column field value with a value from a different field | |
// $billingphone = get_post_meta( $id, '_billing_phone', true ); | |
// $value = sprintf( '<span>'. $billingphone .'</span>', $value ); | |
// ok, so we know the current column is the Attendee Ticket field, so lets grab that meta to manipulate it | |
$event = get_post_meta( $id, 'WooCommerceEventsOrderTickets', true ); | |
// if its not an array then return the value | |
if( ! is_array($event) ) return $value; | |
// if there is an array the lets get into it, and set the initial array as a variable | |
$event = isset($event[1][1]) ? $event[1][1] : ''; | |
// if there are no field data in the array variable spit it out | |
if( sizeof($event) == 0 ) return $value; | |
// go into the array of the next custom field (which is in an array itself) | |
$custom = isset($event['WooCommerceEventsCustomAttendeeFields']) ? $event['WooCommerceEventsCustomAttendeeFields'] : ''; | |
// Set our array of needed data | |
$fields_array = [ | |
__('First Name') => isset($event['WooCommerceEventsAttendeeName']) ? $event['WooCommerceEventsAttendeeName'] : '', | |
__('Last Name') => isset($event['WooCommerceEventsAttendeeLastName']) ? $event['WooCommerceEventsAttendeeLastName'] : '', | |
__('Email') => isset($event['WooCommerceEventsAttendeeEmail']) ? $event['WooCommerceEventsAttendeeEmail'] : '', | |
__('Phone') => isset($event['WooCommerceEventsAttendeeTelephone']) ? $event['WooCommerceEventsAttendeeTelephone'] : '', | |
__('Organization') => isset($custom['fooevents_custom_organization']) ? $custom['fooevents_custom_organization'] : '', | |
__('Title') => isset($custom['fooevents_custom_title']) ? $custom['fooevents_custom_title'] : '', | |
//__('Address') => isset($custom['fooevents_custom_address']) ? $custom['fooevents_custom_address'] : '', | |
//__('City') => isset($custom['fooevents_custom_city']) ? $custom['fooevents_custom_city'] : '', | |
//__('State') => isset($custom['fooevents_custom_state/province']) ? $custom['fooevents_custom_state/province'] : '', | |
//__('Postal Code') => isset($custom['fooevents_custom_postal_code']) ? $custom['fooevents_custom_postal_code'] : '', | |
]; | |
// if the variable has nothing | |
if( ! $event ) return $value; | |
// wrap HTML around the value output | |
$value = '<div>'; | |
// Loop though the data array to set the fields | |
foreach( $fields_array as $label => $field_value ): | |
if( ! empty($field_value) ): | |
// output each field from the array above | |
$value .= '<span><strong>' . $label . '</strong>: ' . $field_value . '</span> <br>'; | |
endif; | |
endforeach; | |
// close the HTML wrapper around the value output | |
$value .= '</div>'; | |
} | |
} | |
return $value; | |
} | |
add_filter( 'ac/column/value', 'ac_my_custom_field_column_value_example', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment