php - Add custom meta column to WooCommerce product listing

We want to add the vendor store name to each product in a column. I know how how to add a column, to get the vendor store name but I have still an empty array when I output the vendor for each product.
Someone able to help out? :)
add_filter( 'manage_edit-product_columns', 'show_product_order',15 );
function show_product_order($columns){
//add column
$columns['vendor_store_name'] = __( 'Vendor');
return $columns;
}
function get_dokan_vendor_shop_name_from_product_test( $product_id ) {
if( empty($product_id) ) return;
$seller = get_post_field( 'post_author', $product_id );
$author = get_user_by( 'id', $seller );
$vendor = dokan()->vendor->get( $seller );
$store_info = dokan_get_store_info( $author->ID );
if ( ! empty( $store_info['store_name'] ) ) {
return $vendor->get_shop_name();
} else {
return;
}
}
add_action( 'manage_product_posts_custom_column', 'vendor_product_column', 10, 2 );
function vendor_product_column( $column, $postid ) {
if ( $column == 'vendor_store_name' ) {
echo get_post_meta( $postid, $store_info, true );
}
}
UPDATE
I'm now trying to output the info directly in the loop where I get the vendor. But still an empty array. It this approach actually possible to get it done?
add_filter( 'manage_edit-product_columns', 'show_product_order',15 );
function show_product_order($columns){
//add column
$columns['vendor_store_name'] = __( 'Vendor');
return $columns;
}
function vendor_product_column( $product_id ) {
foreach ( $products->get_meta as $product ) {
$product = $item->get_product();
$author_id = $product->post->post_author;
$vendor = dokan()->vendor->get( $author_id );
$shop_name = $vendor->get_shop_name();
}
if ( $column == 'vendor_store_name' ) {
echo $store_info;
}
}
add_action( 'manage_product_posts_custom_column', 'vendor_product_column', 10, 2 );
Answer
Solution:
I was able to fix it! Here is the code :)
add_filter( 'manage_edit-product_columns', 'custom_admin_products_store_name_column', 9999 );
function custom_admin_products_store_name_column( $columns ){
$columns['vendor_store_name'] = __( 'Vendor');
return $columns;
}
add_action( 'manage_product_posts_custom_column', 'custom_admin_products_store_name_column_content', 10, 2 );
function custom_admin_products_store_name_column_content( $column, $product_id ){
$seller = get_post_field( 'post_author', $product_id);
$store_info = dokan_get_store_info( $seller );
$store_name = $store_info['store_name'];
if ( $column == 'vendor_store_name' ) {
echo __($store_name);
}
}
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: your lock file does not contain a compatible set of packages. please run composer update.
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.