我创建了一个新产品类型“ 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 );
结果:
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句