I need manage stock enabled with 1 quantity by default.

We're shifting our Forum based support to a more dedicated support system!

We'll be closing our Forum support from 10th June, 2020 and move to Email Support assistance.

  • If you are a WCFM premium add-ons user, contact us- here
  • Want to know more before buying our add-ons? Send Pre sale queries- here
  • If you are a WCFM free user, please open a support ticket at WordPress.org
  • For WCFM App related queries, reach us- here
From now the forum will be read-only!

Viewing 6 reply threads
  • Author
    Posts
    • #68846
      ing.rapparini
      Participant

      When a vendor put on sale a new product, I need manage stock enabled with 1 quantity by default.

      Line to add???

      Thanks

      Attachments:
      You must be logged in to view attached files.
    • #69018
      WCFM Forum
      Member

      Hi,

      Please add this code to your child theme’s functions.php –

      add_filter( 'wcfm_product_fields_stock', function( $stock_fields, $product_id, $product_type ) {
      	if( !$product_id ) {
      		if( isset( $stock_fields['stock_qty'] ) ) {
      			$stock_fields['stock_qty']['value'] = 1;
      		}
      	}
        return $stock_fields;
      }, 50, 3 );

      Thank You

    • #69485
      ing.rapparini
      Participant

      DOES NOT WORK

    • #69659
      kaloomee
      Participant

      Worked for me, Thank you
      When vendor creates new product then the default qty is now 1 instead of 0

    • #69825
      WCFM Forum
      Member

      Great … you are welcome 🙂

    • #70095
      ing.rapparini
      Participant

      ok…I just add also this to enable stock by default…

      add_filter( ‘wcfm_product_fields_stock’, function( $stock_fields, $product_id, $product_type ) {
      if( isset( $stock_fields[‘manage_stock’] ) ) {
      $stock_fields[‘manage_stock’][‘dfvalue’] = ‘enable’;
      }
      return $stock_fields;
      }, 50, 3 );

    • #70268
      WCFM Forum
      Member

      This code is fine.

Viewing 6 reply threads
  • You must be logged in to reply to this topic.