• CobaltCat

    (@cobaltcat)


    Is there a way to have WooCommerce automatically set the default inventory to 1 when products are first input?

Viewing 3 replies - 1 through 3 (of 3 total)
  • the_wpexperts

    (@ukwpexperts)

    With the help of hook you can implement same thing.

    add_action( ‘save_post_product’, ‘set_invenoty_to_one’);
    function set_invenoty_to_one(){
    global $post;
    if ( defined( ‘DOING_AUTOSAVE’ ) && DOING_AUTOSAVE )
    return;
    if ( !isset( $_POST[‘_stock’] ) ){
    update_post_meta( $post->ID, ‘ _stock’, 1);
    update_post_meta( $post->ID, ‘ _stock_status’, ‘instock’);
    }
    }

    Thread Starter CobaltCat

    (@cobaltcat)

    Thank you!

    Does this go into the functions file?

    It can go in functions.php for your child theme or you can use the “My Custom Functions” plugin.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘WooCommerce automatically set default inventory to one’ is closed to new replies.