fahadmahmood8/stock-locations-for-woocommerce

Best practice to notify locations only after order has been paid

Closed this issue · 3 comments

I'm trying to hook into the notification logic. We would need to avoid notifying locations of any stock allocation before the order payment has been received (wait until "processing" status).
Nowadays, because of this line, this happens only after order item creation, independent of order status:

			add_action('woocommerce_new_order_item', array($this, 'newOrderItemAllocateStock'), 10, 3);

So there is no way to impede the notification message. Maybe a filter here would be helpful?

		public static function stock_allocation_notification( $term, $item, $quantity )
		{
                    // New filter here to allow skipping notifications based on status
                    if (!apply_filters('allow_stock_allocation_notification`, $term, $item, $quantity, true)) {
                        return;
                    }

We'd then like to move the notification when the order status changes. In that filter we could store the order item data to pick it up later and do the notification afterwards.
Would such a filter be possible?
Thanks in advance!

So you can use the priority 10 and in the next version it will be available, thank you for bringing it to my attention.

` add_filter('allow_stock_allocation_notification', 'allow_stock_allocation_notification_callback', 9, 4);

if(!function_exists('allow_stock_allocation_notification_callback')){
	function allow_stock_allocation_notification_callback($term, $item, $quantity, $output = true){
		return (boolean)$output;			
	}			
}`

I'm pulling the latest release and will try now. Thanks a lot.

The next version is released, you may test it by updating the plugin as well.