![](/img/trans.png)
[英]Add custom column product visibility to admin product list in Woocommerce 3
[英]WooCommerce: How to add product type next to product name in admin product list
我創建了一個新的產品類型“ 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';
}
}
}
我在管理區域看到了產品類型名稱寫在產品名稱之后的插件,您可以在其中查看所有產品。
我搜索了很多,但找不到這樣做的鈎子。
- 渲染列:名稱。
似乎缺少一個更合適的鈎子,因此一種方法是使用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 ' <span>– ' . ucfirst( $product_type ) . '</span>';
}
}
add_action( 'manage_product_posts_custom_column', 'action_manage_product_posts_custom_column', 20, 2 );
結果:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.