Always put stock on 1?

This topic contains 1 reply, has 2 voices, and was last updated by WCFM Forum WCFM Forum 4 months, 1 week ago.

  • Author
    Posts
  • #87727
    Avatar
    lorisgm21
    Participant

    Hi,
    Is there a possibility that the stock is always at 1? Even if the inventory is deactivated?

    I would like to open a marketplace in which the products can be sold only once. They have to be virtual. You sent me this code: https://wclovers.com/forums/topic/product-sold-individually-and-only-virtual/#post-87520, which works great. But I am always shown that the product is not in stock. Maybe you can give me a code that always sets the inventory to 1?

    Thank you

  • #87970
    WCFM Forum
    WCFM Forum
    Keymaster

    Hi,

    Add this code to your site –

    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 );

    Add this code to your child theme’s functions.php
    In case you do not have child theme then add code using this plugin –¬†https://wordpress.org/plugins/code-snippets/

    Thank You

The topic ‘Always put stock on 1?’ is closed to new replies.