mirror of
https://gh.wpcy.net/https://github.com/mainwp/Code-Snippets-Functions.git
synced 2026-05-01 11:52:25 +08:00
https://stackoverflow.com/questions/77425634/add-ean-custom-column-to-woocommerce-admin-products-list
25 lines
758 B
Text
25 lines
758 B
Text
// Add a new custom column to WooCommerce admin products list
|
|
add_filter('manage_edit-product_columns', 'add_column_product_ean');
|
|
function add_column_product_ean( $columns ) {
|
|
$new_columns = array();
|
|
|
|
foreach ($columns as $key => $label) {
|
|
$new_columns[$key] = $label;
|
|
|
|
if ( $key === 'sku' ) {
|
|
// Add "EAN" column after "SKU" column
|
|
$new_columns['ean'] = __('EAN','woocommerce');
|
|
}
|
|
}
|
|
return $new_columns;
|
|
}
|
|
|
|
// Populate the new column with custom metadata
|
|
add_action('manage_product_posts_custom_column', 'populate_column_product_ean');
|
|
function populate_column_product_ean($column) {
|
|
global $product;
|
|
|
|
if ( $column === 'ean' ) {
|
|
echo $product->get_meta('ean');
|
|
}
|
|
}
|