Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Admin Columns: Add variation name to column
<?php
function ac_column_value_usage( $col_value, $id, AC\Column $column ) {
if ('column-wc-product_details' == $column->get_type()) {
$order = wc_get_order( $id );
foreach ( $order->get_items() as $item_id => $item ) {
if ( $item->get_variation_id() ) {
$product = $item->get_product();
foreach ( $product->get_attributes() as $attribute => $value ) {
$name = term_exists( $value, $attribute ) ? get_term_by( 'slug', $value, $attribute )->name : $value;
$col_value = $col_value .'<br>' . $name;
}
}
}
}
return $col_value;
}
add_filter( 'ac/column/value', 'ac_column_value_usage', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment