• Resolved Jamie

    (@monsterdev)


    I’m trying to have stock between several products updated when one of the products is bought. For example if product A is bought then B and C stock is also reduced. It seems like your plugin might be able to do this, but I can’t get it to work…

    Only the stock of the purchased product and the attribute stock is reduced, but none of the other products sharing the same attribute update their stock levels.

    I hope what I’m trying to do makes sense. Please let me know if this is possible to do.

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author Mewz

    (@mewz)

    Hi @monsterdev! ??

    I’m sorry to say that this is not a feature that our plugin currently offers. However, product stock synchronization is something we’re actively working on and will release very soon in our PRO version.

    If you prefer to stick with the free version, this can be done fairly easily by adding a custom hook (e.g. in your theme’s functions.php file). Below is an example snippet on how to get started with this:

    
    use Mewz\WCAS\Models\AttributeStock;
    
    add_action('mewz_attribute_stock_saved', function(AttributeStock $stock)
    {
    	if ($stock->id() === 123) {
    		// Find your products, e.g.
    		$products = wc_get_products([
    			'category' => 'shirts',
    			'status' => 'publish',
    			'limit' => -1,
    		]);
    
    		/** @var WC_Product $product */
    		foreach ($products as $product) {
    			$quantity = $stock->quantity();
    
    			if ($product->get_stock_quantity('edit') != $quantity) {
    				$product->set_stock_quantity($quantity);
    				$product->save();
    			}
    		}
    	}
    });
    

    This is a very simple function that will update the stock quantity of all published products in the Shirts category whenever the stock quantity of the attribute stock item with ID 123 is updated. Of course this can be expanded to update your product stock however you like.

    If there’s anything further we can assist you with, please let us know!

    Thread Starter Jamie

    (@monsterdev)

    Hey thanks for the reply! I’ll see if I can get that code to work otherwise I may just have to wait it out and look at upgrading.. I’ve been searching for a few days and I can’t find anything that can do this type of shared product stock in Woocommerce.

    Do you have an ETA on the product stock synchronization feature by any chance?

    Plugin Author Mewz

    (@mewz)

    No problem. I can’t give an exact date, but we’re hoping to release it by the end of the month.

    Thread Starter Jamie

    (@monsterdev)

    Oh that’s great. Looking forward to it!

    Hello, so how about the update? We bought the plugin yesterday and need the same functionality.

    Best,

    Sylwia

    Plugin Author Mewz

    (@mewz)

    Hi @sylwiaofwarsaw!

    We spoke with @monsterdev via our direct support channel and figured out a better solution for his use case that doesn’t involve explicitly updating his product stock.

    Perhaps you could give me some more details about what you’re trying to achieve with this feature?

    Our plugin will already display the correct available product stock (according to available attribute stock) on the frontend and prevent over-purchasing.

    Hi Mewz,

    thank you for answering me.

    We have bags with variations. However, each variation is created as its own product with variations. I.e. there’s a yellow bag X with white and black variations, and white bag X with yellow and black variations, and black bag X with yellow and white variations.

    We also have a plugin for swatches that doesn’t show a variation in the store if that variation is soldout.

    And now we also have your plugin, which we thought would be the solution for us, but it doesn’t change the stock everywhere.

    In practice it looks like this:

    Let’s say we have 3 white bags X. Someone buys one white as a variation to the yellow bag. Then the attribute stock for it changes to 2, but its stock number at white and black bags is still 3. That in itself is not a problem because your plugin will not let it to be oversold.

    However, if someone buys all three from one of those places, then it’ll disappear only in that one place. It’ll still be showing at the store as available from the other places. People won’t be able to buy it, but it will look bad that we display a product that doesn’t exist.

    There’s also another problem. If we update the stock at the stock attribute list (let’s say we’ll add 10) it’ll still show as unavailable as a variation to the yellow bag, while the other places (white and black) will allow people to buy only 3 because that was the limit we set previously and it didn’t change throughout all the operations.

    I really hope you can help me with that.

    Best,
    Sylwia

    Plugin Author Mewz

    (@mewz)

    Ok, as I understand it you want your products linked together via attributes, so they can be bought directly or from each other.

    It’s a bit tricky, but it is possible to do. You just need to create a new attribute to act as the product stock, instead of managing the product stock directly.

    For example, add attribute Bag Stock with terms Yellow X, White X, Black X. Then go into your Attribute Stock items and add a new match under the Attributes tab for each term.

    Then all you need to do is assign each attribute/term to its respective product (with “Used for variations” disabled). With manage stock disabled on the product, it will now use attribute stock only.

    https://pasteboard.co/J4Gnlng.png – Example of how the attribute stock matches should be added.

    https://pasteboard.co/J4GpBxh.png – Example of how the product attributes should be added.

    OK, I admit I’m not sure I understand your solution, so I’ll explain what I have now, and maybe you can tell me what would be different if I changed it.

    This is a picture of my rings collection. One ring has 5 different colours. Each of those colours is shown in the store archive page as a separate dummy product (it’s done via different name and featured picture). But in fact no variable is chosen at this point. That’s important, otherwise the thumbs gallery won’t work as we want it in archive pages.

    https://pasteboard.co/J4IPGH3.png

    Each of those “dummy products” has 5 different shared variables. Each variable, which is an extended colour name, is present in every “dummy product” and stock is managed only on the variable level. Each variable has one name and SKU.

    So say “white ring x” is the name of colour for the ring X in white color, has its own SKU, and is repeated 5 times in each of those dummy products. All in all there are 5 variables (products in particular colours) but repeated 25 times via the store.

    Here’s how the attributes for colour names and their stock are made:
    https://pasteboard.co/J4LEumg.png

    And here’s how they’re added to products:
    https://pasteboard.co/J4LB5Ne.png

    How is your solution different? Also, what happens when you have Bag Stock Black sold in Yellow colour, or, say, a yellow ring?

    Additionally, I cannot disable product’s stock on the variable level. If I do that the “white ring” will disappear from the store. That’s how the swatches work.

    Best,

    Sylwia

    Plugin Author Mewz

    (@mewz)

    Well that’s even simpler than I thought. And it looks like you’ve already set up all the necessary attribute stock for it.

    The only missing part is the stock that’s managed at the variation level. Ideally you want to disable “Manage stock” for each variation, but keep stock status set to “In stock”. Our plugin will override the stock automatically to set the correct levels on the frontend (as long as the “Limit product stock” setting is enabled in each attribute stock item).

    The product stock overriding is handled internally, so it shouldn’t affect the operation of your swatches plugin if it uses the correct WooCommerce methods.

    If you are still not having any luck, please contact us via our direct support channel on CodeCanyon so that we can work with you to investigate further. This is a fairly straightforward use case for attribute stock, so it’s just a matter of getting the swatches plugin to work alongside it.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Update stock for all products’ is closed to new replies.