source

WooCommerce:관리 제품 목록에서 제품명 옆에 제품 유형을 추가하는 방법

bestscript 2023. 9. 17. 17:55

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

모든 제품을 볼 수 있는 관리 영역에서 제품명 뒤에 제품 종류 이름이 적혀있는 플러그인을 본 적이 있습니다.

enter image description here

많이 찾아봤지만 이렇게 할 수 있는 갈고리를 찾을 수가 없었습니다.

https://github.com/woocommerce/woocommerce/blob/4.1.0/includes/admin/list-tables/class-wc-admin-list-table-products.php#L157-L203

  • 렌더 열: 이름.

좀 더 적합한 후크가 없는 것 같아요, 그래서 한 가지 방법은,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 );

결과:

Product type next to product name

언급URL : https://stackoverflow.com/questions/62301223/woocommerce-how-to-add-product-type-next-to-product-name-in-admin-product-list