1

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?

LoicTheAztec
  • 184,753
  • 20
  • 224
  • 275
Exdefoot
  • 35
  • 3

1 Answers1

1

Updated - The following code will select "variable" by default on the product type selector 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');
    });
    </script>
    <?php
    endif;
}

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

LoicTheAztec
  • 184,753
  • 20
  • 224
  • 275
  • Hi Loic, nice but I don't want to get rid of all the other ones (if someday something changes), just wanted to have Variable on top or selected by default. Do you have any other idea? – Exdefoot Apr 17 '19 at 14:34
  • 1
    @Exdefoot Updated… It should be convenient now – LoicTheAztec Apr 17 '19 at 14:51
  • 1
    Hi Loic, perfect! I just needed to add inverted commas to $pagenow === 'post-new.php' as it crashed my site otherwise. T'es un boss :) – Exdefoot Apr 17 '19 at 20:00