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

微笑、不失礼 提交于 2021-01-28 05:40:59

问题


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?


回答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.



来源:https://stackoverflow.com/questions/55728698/set-the-product-type-to-variable-by-default-in-admin-new-product-pages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!