Created
January 31, 2022 11:14
-
-
Save finalwebsites/6c98ca05c0e9fe19bc5ee65d915b101b to your computer and use it in GitHub Desktop.
Admin Columns: Add variation name to column
This file contains 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 | |
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