Home Forums Theme Support Dokan Default stock set to 1

This topic is: resolved

Tagged: , ,

This topic contains 2 replies, has 2 voices, and was last updated by  towhid 4 years, 4 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #32952

    Stephen
    Member
    Post count: 16

    Hi,

    I'm using dokan plugin. I want to make it so when a user adds a product, stock management is turned on by default and the stock is set to 1.

    Can you help me do that?

    #32954

    Stephen
    Member
    Post count: 16

    I have managed to do this myself. This is how I did it:

    Inside the file classes/template-shortcodes.php around line 145 just after

    $post_data = apply_filters( 'dokan_insert_product_post_data', array(
          'post_type'    => 'product',
          'post_status'  => $product_status,
          'post_title'   => $post_title,
          'post_content' => $post_content,
          'post_excerpt' => $post_excerpt,
    ) );
    
    $product_id = wp_insert_post( $post_data );
    

    I have added the following code

    //Set default stock to 1
    update_post_meta( $product_id, '_manage_stock', 'yes'  );
    update_post_meta( $product_id, '_stock', '1'  );

    I hope this helps the other people trying to do this.

    #32975

    towhid
    Participant
    Post count: 4505

    Hello Stephen,

    Very well solution. I have tested and it works for me.

    Hope it will help other people if they want to.

    Thank You ๐Ÿ™‚

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Default stock set to 1’ is closed to new replies.