phpjquerywordpresswoocommercewp-admin

Set the product type to "variable" by default in admin new product pages


I'm creating a WooCommerce store with variable products only. When creating new products I always need to manually change the Product Data to Variable Product. When you have hundreds of products, this is becoming kind of a pain :)

I've searched around the Internet but wasn't able to find anything...

<php?
// Code here
?>

I'm looking for a PHP snippet to set Variable Product as default when creating new products, any ideas?


Solution

  • Updated - The following code will select "variable" by default on the product type select field, in backend for new product pages:

    add_action( 'admin_footer', 'product_type_selector_filter_callback' );
    function product_type_selector_filter_callback() {
        global $pagenow, $post_type;
    
        if( $pagenow === 'post-new.php' && $post_type === 'product' ) :
        ?>
        <script>
        jQuery(function($){
            $('select#product-type').val('variable').change();
        });
        </script>
        <?php
        endif;
    }
    

    Code goes in function.php file of your active child theme (or active theme). Tested and works.