Multi Vendor Marketplace Plugin | WCFM Marketplace › Forums › WC Marketplace › Set every vendor product as a single purchase and disable stock management
Tagged: book, disable, fraud, management, product, single, single purchase, stock, vendor
- This topic has 3 replies, 2 voices, and was last updated 4 years, 9 months ago by WCFM Forum.
- AuthorPosts
- October 4, 2019 at 2:30 am #85011contatoappParticipant
If I enable stock management for all vendors, they can manually set a product as a single purchase (meaning there’s only 1 in stock).
I’m building a book marketplace where vendors will anounce their new/used books, but to stop them from bundling new and used books in a single purchase (since the books are gonna be categorized under their conservation status), I want every vendor product to be registered as a single purchase, preventing fraud.
But even if I disable stock management for vendors, users can still select the amount of products on the product’s page (see attached image) because, I assume, since there’s no stock management, that means the products will be delivered on demand and/or there’s an indefinite amount in stock.
Is that possible? Thanks in advance!
Attachments:
You must be logged in to view attached files. - October 11, 2019 at 11:17 am #86199WCFM ForumMember
Hi,
Keep stock management enable and add this code to your site, hence vendors will not able to manage stock from their products –
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 );
It will set product stock always “1” as well.
Thank You
- January 15, 2020 at 7:12 pm #102146contatoappParticipant
Hello. Awesome, this works just as expected.
If I could ask something else, I’d like to know if it’s possible to set this condition only to store vendors, but still enable stock management for store managers and admin.
Thanks in advance.
- February 7, 2020 at 11:44 am #106043WCFM ForumMember
Hi,
Sure, use this revised code to make this applicable only for vendor users –
add_filter( 'wcfm_product_fields_stock', function( $stock_fields, $product_id, $product_type ) { if( wcfm_is_vendor() ) { 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
- AuthorPosts
- The topic ‘Set every vendor product as a single purchase and disable stock management’ is closed to new replies.