Best Multi Vendor Marketplace Plugin for WordPress › Forums › WCFM – Ultimate › Product stock
- This topic has 3 replies, 2 voices, and was last updated 7 years, 9 months ago by
WCFM Forum.
- AuthorPosts
- February 9, 2019 at 3:54 am #47322
Logan Dundon
GuestHi 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;}
- February 9, 2019 at 6:06 am #47361
WCFM Forum
MemberHi,
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
- February 9, 2019 at 9:18 pm #47476
Logan Dundon
GuestThanks 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?
- February 10, 2019 at 5:55 am #47493
WCFM Forum
MemberHi,
“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
- AuthorPosts
- The topic ‘Product stock’ is closed to new replies.