fahadmahmood8/stock-locations-for-woocommerce

Using Woocommerce hooks to update stock to improve compatibility

Closed this issue · 3 comments

We have an issue with making this plugin compatible with the plugin "Back In Stock Notifications". Notifications in this plugin are connected to Woocommerce product stock hooks which are not being called when using this plugin (see relevant hooks below). If these can be integrated with this plugin it should solve the compatibility issue with that plugin, and might help with similar issues listed here :)

Status updates

  • woocommerce_product_set_stock_status
  • woocommerce_variation_set_stock_status

Stock updates

  • woocommerce_product_set_stock
  • woocommerce_variation_set_stock

Might be enough to edit this code: src/helpers/helper-slw-order-item.php, line 143-156?

// update product WC stock
if( $mainProduct->get_stock_quantity() >= $totalQtyAllocated ) { // don't allow to decrease below zero
	$stock_qty = $mainProduct->get_stock_quantity() - $totalQtyAllocated;
	// update stock
	
	update_post_meta( $mainProductId, '_stock', $stock_qty );
	// update stock status
	SlwProductHelper::update_wc_stock_status( $mainProductId, $stock_qty );

	// allow other functions to deduct WC stock on the main variation product
	if( $mainProduct->get_type() == 'variation' ) {
		do_action( 'slw_allow_variation_product_stock_reduce', $mainProduct->get_parent_id() );
	}
}

I would like you to have a look on the following file and function. Actually stock update is being triggered from here.
helper-slw-product.php > update_wc_stock_status

I need more input from you so I can understand the issue correctly.

I made a pull request with some code changes that fixed this for me. Not sure how to connect it to this issue, but please take a look :)

Thank you