Closed ajlowndes closed 5 years ago
Hmm, I just realised there is an alternative (simpler/cleaner) way to write the second function to re-use one of the plugin's own functions...
The function can be written as: (note I have commented out the whole block that is made redundant)
public static function add_registration_details_column_content ( $column ) {
global $post, $the_order;
if ( empty( $the_order ) || $the_order->get_id() != $post->ID ) {
$the_order = wc_get_order( $post->ID );
}
if ( $column === 'registration_booked' ){
echo WC_Registrations_Checkout::registrations_field_display_admin_order_meta($the_order);
// $items = $the_order->get_items();
// $patterns = array ('/(19|20)(\d{2})-(\d{1,2})-(\d{1,2})/',
// '/\{"type":.*":/',
// '/\[/',
// '/"/',
// '/\,/',
// '/\]/',
// '/\}/');
// $replace = array ('\4/\3/\1\2', '', '', '', ' to ', '', '');
// foreach ( $items as $item ) {
// $product_name = $item['name'];
// $product_id = $item['product_id']; // post id
// $product_variation_id = $item['variation_id'];
// echo preg_replace($patterns, $replace, "$product_name (ID #$product_variation_id)<br>");
// }
}
}
}
The only problem with this is, the column shows NOTHING if the order was added manually from the website back-end via the "add order" button, which I do a lot. I guess I should be adding registrations from the front end instead. But anyway - I'll leave it to you to decide which method is cleaner to put into the plugin itself...
Great addition @ajlowndes! Sorry to test it just now, I was passing for some things last months.
You're right, it can be replaced for one of the plugin functions, and maybe that function makes more sense to be in the class WC_Registrations_Ordes
than WC_Registrations_Checkout
, some organization improvements I'm considering for next releases.
Thank you!
Finally managed to figure it out. Added a new class to do it, as you suggested.