隐藏掉woocommerce Product data里面的选项卡
目录
在某种情况下,想隐藏掉产品详情里面的woocommerce Product data里面的选项卡,然后增加自定义选项卡。
添加入子主题functions.php 即可隐藏,不想隐藏的删掉对应行,或者前面加注示//,如下
//隐藏选项卡 add_filter( 'woocommerce_allow_marketplace_suggestions', '__return_false' ); add_filter( 'woocommerce_product_data_tabs', 'custom_product_data_tabs' ); function custom_product_data_tabs( $tabs ) { //unset( $tabs['general'] ); unset( $tabs['inventory'] ); unset( $tabs['shipping'] ); unset( $tabs['linked_product'] ); unset( $tabs['attribute'] ); unset( $tabs['variations'] ); unset( $tabs['advanced'] ); return $tabs; }
//隐藏产品类型 add_filter( 'product_type_selector', 'remove_product_types' ); function remove_product_types( $types ){ unset( $types['grouped'] ); unset( $types['external'] ); unset( $types['variable'] ); return $types; }
//其它选项 add_filter( 'product_type_options', function( $options ) { // remove "Virtual" checkbox if( isset( $options[ 'virtual' ] ) ) { unset( $options[ 'virtual' ] ); } // remove "Downloadable" checkbox if( isset( $options[ 'downloadable' ] ) ) { unset( $options[ 'downloadable' ] ); } return $options; } );
//去掉产品管理筛选Virtual 和 Downloadable add_filter( 'woocommerce_products_admin_list_table_filters', function( $filters ) { if( isset( $filters[ 'product_type' ] ) ) { $filters[ 'product_type' ] = 'misha_product_type_callback'; } return $filters; }); function misha_product_type_callback(){ $current_product_type = isset( $_REQUEST['product_type'] ) ? wc_clean( wp_unslash( $_REQUEST['product_type'] ) ) : false; $output = '<select name="product_type" id="dropdown_product_type"><option value="">Filter by product type</option>'; foreach ( wc_get_product_types() as $value => $label ) { $output .= '<option value="' . esc_attr( $value ) . '" '; $output .= selected( $value, $current_product_type, false ); $output .= '>' . esc_html( $label ) . '</option>'; } $output .= '</select>'; echo $output; }