Skip to content

Instantly share code, notes, and snippets.

@finalwebsites
Created January 31, 2022 11:14
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 finalwebsites/6c98ca05c0e9fe19bc5ee65d915b101b to your computer and use it in GitHub Desktop.
Save finalwebsites/6c98ca05c0e9fe19bc5ee65d915b101b to your computer and use it in GitHub Desktop.
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