Product stock

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 3 reply threads
  • Author
    Posts
    • #47322
      Logan Dundon
      Guest

      Hi WCFM,
      I love the Ultimate interface and recently found some html that allowed the admin to automatically set stock for a product in WC Vendors Pro. I was hoping to find a way to do the same in Ultimate. The goal is to restrict vendors to post only 1 unit per product at time- that way when a customer buys the product it disappears off the site. If there’s a way to do this or a way to modify the code below, that’d be great.
      Thanks!

      // Changes the default value for manage stock checkbox to checked

      add_filter( ‘wcv_product_manage_stock’, ‘change_default_manage_stock’ );
      function change_default_manage_stock() {

      $field[‘post_id’] = $post_id;
      $field[‘id’] = ‘_manage_stock’;
      $field[‘wrapper_class’] = ‘show_if_simple show_if_variable’;
      $field[‘label’] = __( ‘Manage stock?’, ‘wcvendors-pro’ );
      $field[‘description’] = __( ‘Enable stock management at product level’, ‘wcvendors-pro’ );
      $field[‘type’] = ‘checkbox’;
      $field[‘value’] = ‘yes’; // This checks the checkbox
      return $field;

      }

      // Changes the default value for sold individually checkbox to checked

      add_filter( ‘wcv_product_sold_individually’, ‘change_default_sold_individually’ );
      function change_default_sold_individually() {

      $field[‘post_id’] = $post_id;
      $field[‘id’] = ‘_sold_individually’;
      $field[‘wrapper_class’] = ‘show_if_simple show_if_variable’;
      $field[‘label’] = __( ‘Sold Individually’, ‘wcvendors-pro’ );
      $field[‘desc_tip’] = ‘true’;
      $field[‘description’] = __( ‘Enable this to only allow one of this item to be bought in a single order’, ‘wcvendors-pro’ );
      $field[‘type’] = ‘checkbox’;
      $field[‘value’] = ‘yes’; // This checks the checkbox
      return $field;

      }

      // Changes the default value for stock qty to 1

      add_filter( ‘wcv_product_stock_qty’, ‘change_default_stock_qty’ );
      function change_default_stock_qty() {

      $field[‘post_id’] = $post_id;
      $field[‘id’] = ‘_stock’;
      $field[‘label’] = __( ‘Stock Qty’, ‘wcvendors-pro’ );
      $field[‘wrapper_start’] = ‘<div class=”all-100″>’;
      $field[‘wrapper_end’] = ‘</div>’;
      $field[‘desc_tip’] = ‘true’;
      $field[‘description’] = __( ‘Stock quantity.’, ‘wcvendors-pro’ );
      $field[‘type’] = ‘number’;
      $field[‘data_type’] = ‘stock’;
      $field[‘custom_attributes’][‘step’] = ‘any’;
      $field[‘value’] = ‘1’; // This sets the quantity
      return $field;

      }

    • #47361
      WCFM Forum
      Member

      Hi,

      Thanks for get in touch with us.

      Well, here is WCFM code for the same purpose, I have hide those fields as well.

      Add this 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['manage_stock'] ) ) {
      			$stock_fields['manage_stock']['dfvalue'] = 'enable';
      		}
      		if( isset( $stock_fields['stock_qty'] ) ) {
      			$stock_fields['stock_qty']['value'] = 1;
      		}
      		if( isset( $stock_fields['sold_individually'] ) ) {
      			$stock_fields['sold_individually']['dfvalue'] = 'enable';
      		}
      	}
      	$stock_fields = wcfm_hide_field( 'manage_stock', $stock_fields );
      	$stock_fields = wcfm_hide_field( 'stock_status', $stock_fields );
      	$stock_fields = wcfm_hide_field( 'stock_qty', $stock_fields );
      	$stock_fields = wcfm_hide_field( 'backorders', $stock_fields );
      	$stock_fields = wcfm_hide_field( 'sold_individually', $stock_fields );
        return $stock_fields;
      }, 50, 3 );

      Thank You

    • #47476
      Logan Dundon
      Guest

      Thanks again this code worked great! I was wondering though if there was any code to keep the inventory panel on in vendor capabilities but hide it on the product form?

    • #47493
      WCFM Forum
      Member

      Hi,

      “if there was any code to keep the inventory panel on in vendor capabilities but hide it on the product form?”
      – Sorry, this will not work.

      Thank You

Viewing 3 reply threads
  • The topic ‘Product stock’ is closed to new replies.