亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

WooCommerce:如何在管理產品列表中的產品名稱旁邊添加產品類型

WooCommerce:如何在管理產品列表中的產品名稱旁邊添加產品類型

PHP
www說 2023-05-12 15:50:02
我創建了一個新的產品類型“ 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 '&nbsp;<span>&ndash; ' .? ucfirst( $product_type ) . '</span>';

? ? }

}

add_action( 'manage_product_posts_custom_column', 'action_manage_product_posts_custom_column', 20, 2 );

結果:

http://img1.sycdn.imooc.com/645defe200017dc104990391.jpg

查看完整回答
反對 回復 2023-05-12
  • 1 回答
  • 0 關注
  • 148 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號