add_filter('manage_edit-shop_order_columns', 'wtwh_order_items_column' );
function wtwh_order_items_column( $order_columns ) {
$order_columns['order_products'] = "Product SKU";
return $order_columns;
}
add_action( 'manage_shop_order_posts_custom_column' , 'wtwh_order_items_column_cnt', 10, 2 );
function wtwh_order_items_column_cnt( $column, $post_id ) {
if( $column == 'order_products' ) {
// Get order object
$order = wc_get_order( $post_id );
// Check if order exists and is valid
if ( ! $order ) {
return;
}
// Get items from the order
$order_items = $order-get_items();
// Loop through items
foreach( $order_items as $order_item_id = $order_item ) {
// Get product ID
$product_id = $order_item-get_product_id();
// Get product object
$product = wc_get_product( $product_id );
// Product checking
$sku = $product ? ' - ' . $product-get_sku() : '';
// Output product name and SKU
echo ''. $order_item-get_name() . ''. $sku . '
';
}
}
}
KShs 3,375.00
Reviews
There are no reviews yet.