WooCommerce:如何在管理产品列表中的产品名称旁边添加产品类型

我创建了一个新的产品类型“ Crush Video Product”。它从其自定义选项卡中正确保存所有元字段。


// add a product type

add_filter( 'product_type_selector', 'crush_add_custom_product_type' );


function crush_add_custom_product_type( $types ){

    $types[ 'crush_video_product' ] = __( 'Group Video Class' );

    return $types;

}


// Initiate Class when plugin is loaded

add_action( 'plugins_loaded', 'crush_create_custom_product_type' );


function crush_create_custom_product_type(){

    // declare the product class


    class WC_Product_Crush_Video_Product extends WC_Product{

        public function __construct( $product ) {

            $this->product_type = 'crush_video_product';

            parent::__construct( $product );

            // add additional functions here

        }


        // Needed since Woocommerce version 3

        public function get_type() {

            return 'crush_video_product';

        }

    }

}

我见过一些插件,产品类型的名称写在管理区域的产品名称之后,您可以在管理区域看到所有产品。

http://img.mukewang.com/645defcf0001054e06530134.jpg

我搜索了很多,但找不到一个钩子来做到这一点。



www说
浏览 124回答 1
1回答

元芳怎么了

渲染列:名称。似乎缺少更合适的钩子,所以一种方法是,manage_product_posts_custom_column如果需要,使用一些 CSS 来显示function action_manage_product_posts_custom_column( $column, $postid ) {            if ( $column == 'name' ) {        // Get product        $product = wc_get_product( $postid );                // Get type        $product_type = $product->get_type();                // Output        echo '&nbsp;<span>&ndash; ' .  ucfirst( $product_type ) . '</span>';    }}add_action( 'manage_product_posts_custom_column', 'action_manage_product_posts_custom_column', 20, 2 );结果:
打开App,查看更多内容
随时随地看视频慕课网APP