将自定义元列添加到 WooCommerce 产品列表 [英] Add custom meta column to WooCommerce product listing

查看:37
本文介绍了将自定义元列添加到 WooCommerce 产品列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们希望为列中的每个产品添加供应商商店名称.我知道如何添加列以获取供应商商店名称,但是当我为每个产品输出供应商时,我仍然有一个空数组.

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.

有人能帮忙吗?:)

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 );
    }
}

更新

我现在尝试直接在我获得供应商的循环中输出信息.但仍然是一个空数组.这种方法真的可以完成吗?

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 );

推荐答案

我能够修复它!这是代码:)

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);
        
    }
}

这篇关于将自定义元列添加到 WooCommerce 产品列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆