I use woocommerce v. 7.9.0
I inserted the following code in the theme’s functions.php file but no new column appears on the wp-admin/edit.php?post_type=product page.
Does anyone know how to solve it?
// Add "EAN" column to the products table in WooCommerce
function add_column_product_ean($columns) {
$new_columns = array();
foreach ($columns as $column_name => $column_info) {
$new_columns[$column_name] = $column_info;
if ($column_name === '_sku') {
// Add "EAN" column after "SKU" column
$new_columns['ean'] = 'EAN';
}
}
return $new_columns;
}
add_filter('manage_edit-product_columns', 'add_column_product_columns');
// Populate the "EAN" column with the custom field data
function populate_column_product_ean($column, $post_id) {
if ($column === 'ean') {
$ean_value = get_post_meta($post_id, 'ean', true);
echo $ean_value;
}
}
add_action('manage_product_posts_custom_column', 'populate_column_product_ean', 10, 2);