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 );
question from:
https://stackoverflow.com/questions/65944020/add-custom-meta-column-to-woocommerce-product-listing 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…