• Resolved retepuang

    (@retepuang)


    I am selling tickets for sports events. Each event takes place in the same stadium.

    The customer shall select his tribune block wich is linked to Attribute Stock. Each block of a tribune has a defined number or capacity of seats (number of seats = stock volume).

    Each event has his own WC-product. By starting sales of the first event all tribunes will have 100% stock volume (e.g.: Block A = 100 seats, Block B = 80 seats …). By selling the first ticket of Block A, the stock volume will be reduced by 1 to 99 seats). This works perfectly well.

    I now need to duplicate and rename the product for the next event. All stock volume shall be reset to 100% of its capacity. In other words: The new product shall inherit the total stock volume of an empty stadium which was set up before starting sales of the fist event.

    Is this possible?

    • This topic was modified 4 years, 1 month ago by retepuang.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Mewz

    (@mewz)

    Sure it’s possible, but not without a little code. Something like this should do it:

    add_action('woocommerce_product_duplicate', function($duplicate, $product)
    {
    	// List your attribute stock items by ID => quantity
    	$stocks = [
    		1111 => 100, // Block A
    		2222 => 80, // Block B
    		3333 => 50, // etc.
    	];
    
    	foreach ($stocks as $id => $quantity) {
    		$stock = mewz_wcas_get_stock($id);
    
    		if ($stock->exists()) {
    			$stock->set_quantity($quantity);
    			$stock->save();
    		}
    	}
    }, 10, 2);

    This will simply update the stock quantities to the specified values whenever any product is duplicated. Of course it could be expanded to only trigger when specific products are duplicated, or added, etc.

    The ID’s used in the $stocks array can be found in the URL of each item under Products > Attribute Stock (e.g. ...&post=1111).

    If you’re not familiar with adding custom code to WordPress, I highly recommend using the Code Snippets plugin.

    Saul

    (@slightlyfaulty)

    DELETED

    Plugin Author Mewz

    (@mewz)

    We’re going to close this for now as we haven’t heard back from you @retepuang.

    If you need any further help, please feel free to reply here or contact us on our direct support channel.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Inheritance of stock to products’ is closed to new replies.