Created
June 1, 2021 19:00
-
-
Save manuelhudec/d55751247fe784773d219ccef6fa2650 to your computer and use it in GitHub Desktop.
WooCommerce - disable downloadable & virtual products
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function my_remove_product_type_options( $options ) { | |
// uncomment this if you want to remove virtual too. | |
if ( isset( $options['virtual'] ) ) { | |
unset( $options['virtual'] ); | |
} | |
if ( isset( $options['downloadable'] ) ) { | |
unset( $options['downloadable'] ); | |
} | |
return $options; | |
} | |
add_filter( 'product_type_options', 'my_remove_product_type_options' ); | |
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; | |
} | |
add_filter('add_meta_boxes', function() { | |
remove_meta_box('woocommerce-order-downloads', 'shop_order', 'normal'); | |
}, 99 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment