WooCommerce product variations: Auto enable Manage Stock and set stock quantity

Dev

On Admin Woocommerce product pages, for variable products, on "Variations" settings, for all product variations, I would like to have Manage Stock option enabled by default with the Stock Quantity option set to 1.

Using Get Woocommerce to Manage Stock as a default answer code, I am able to do it for the default inventory tab (for the parent variable product).

I even tried Woocommerce: Creating variations - Manage stock checked by default answer code, but it didn't worked form me.

Any help will be appreciated.

LoicTheAztec

For info, woocommerce_product_variation_get_manage_stock hook doesn't exist anymore.

Based on jQuery code, the following will enable Manage Stock and will set Stock Quantity to 1, for all product variations:

add_action( 'admin_footer', 'custom_admin_product_variations_js' );
function custom_admin_product_variations_js() {
    global $post_type;

    if ( 'product' === $post_type ) :
    ?><script type='text/javascript'>
    jQuery( function($) {
        $('#variable_product_options').on( 'change', function(){
            $('input.variable_manage_stock').each( function(){
                if( ! $(this).is(':checked') ){
                    $(this).attr('checked', 'checked').closest('div').find('.wc_input_stock').val(1);
                }
            });
        });
    });
    </script><?php
    endif;
}

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

echo woocommerce stock quantity of a particular product id

From Dev

Greying out out-of-stock product variations (WooCommerce)

From Dev

Greying out out-of-stock product variations (WooCommerce)

From Dev

Woocommerce - manage stock on attributes

From Java

Set a max displayed available stock quantity on Woocommerce archives for variable products

From Dev

Woocommerce: Minimum Quantity for Overall Product Category, not variations

From Dev

Woocommerce: Minimum Quantity for Overall Product Category, not variations

From Dev

Woocommerce product query for stock status

From Dev

How to get the stock quantity of an article from woocommerce?

From Dev

How get variation's stock quantity woocommerce

From Dev

Prestashop - Cancelled order product quantity not increased in stock quantity

From Dev

Prestashop - Cancelled order product quantity not increased in stock quantity

From Dev

hide product attributes if their variations are not set (WooCommerce)

From Dev

Move "in stock" up on Woocommerce product page

From Dev

How to echo "# in stock" from product page on WooCommerce?

From Dev

Enable decimal quantities and stock for WooCommerce products

From Dev

Disable add to cart button based on WooCommerce product custom stock status

From Dev

Hide Add to cart block when a variable product is out of stock in Woocommerce

From Dev

About update product stock status function in WooCommerce 3

From Dev

Query for update stock quantity in transaction

From Dev

Query for maintaining stock of product

From Dev

Woocommerce product variations layout change

From Dev

Add stock option in woocommerce

From Dev

woocommerce stock notification priority

From Dev

Change Woocommerce In Stock/Out Stock Text

From Dev

Allow customer to set the product quantity globally on Woocommerce products

From Dev

Auto set active subitem segment value in Stock Item screen

From Dev

Displaying the 'out of stock' string on shop page but not the stock quantity.

From Dev

Use of "FOR UPDATE" during Magento stock quantity update

Related Related

  1. 1

    echo woocommerce stock quantity of a particular product id

  2. 2

    Greying out out-of-stock product variations (WooCommerce)

  3. 3

    Greying out out-of-stock product variations (WooCommerce)

  4. 4

    Woocommerce - manage stock on attributes

  5. 5

    Set a max displayed available stock quantity on Woocommerce archives for variable products

  6. 6

    Woocommerce: Minimum Quantity for Overall Product Category, not variations

  7. 7

    Woocommerce: Minimum Quantity for Overall Product Category, not variations

  8. 8

    Woocommerce product query for stock status

  9. 9

    How to get the stock quantity of an article from woocommerce?

  10. 10

    How get variation's stock quantity woocommerce

  11. 11

    Prestashop - Cancelled order product quantity not increased in stock quantity

  12. 12

    Prestashop - Cancelled order product quantity not increased in stock quantity

  13. 13

    hide product attributes if their variations are not set (WooCommerce)

  14. 14

    Move "in stock" up on Woocommerce product page

  15. 15

    How to echo "# in stock" from product page on WooCommerce?

  16. 16

    Enable decimal quantities and stock for WooCommerce products

  17. 17

    Disable add to cart button based on WooCommerce product custom stock status

  18. 18

    Hide Add to cart block when a variable product is out of stock in Woocommerce

  19. 19

    About update product stock status function in WooCommerce 3

  20. 20

    Query for update stock quantity in transaction

  21. 21

    Query for maintaining stock of product

  22. 22

    Woocommerce product variations layout change

  23. 23

    Add stock option in woocommerce

  24. 24

    woocommerce stock notification priority

  25. 25

    Change Woocommerce In Stock/Out Stock Text

  26. 26

    Allow customer to set the product quantity globally on Woocommerce products

  27. 27

    Auto set active subitem segment value in Stock Item screen

  28. 28

    Displaying the 'out of stock' string on shop page but not the stock quantity.

  29. 29

    Use of "FOR UPDATE" during Magento stock quantity update

HotTag

Archive