我創建了一個新的產品類型“ Crush Video Product”。它從其自定義選項卡中正確保存所有元字段。// add a product typeadd_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 loadedadd_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'; } }}我見過一些插件,產品類型的名稱寫在管理區域的產品名稱之后,您可以在管理區域看到所有產品。我搜索了很多,但找不到一個鉤子來做到這一點。
1 回答

元芳怎么了
TA貢獻1798條經驗 獲得超7個贊
渲染列:名稱。
似乎缺少更合適的鉤子,所以一種方法是,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 );
結果:
- 1 回答
- 0 關注
- 148 瀏覽
添加回答
舉報
0/150
提交
取消