Forum

Thread tagged as: Question, Shop

Exclude two stock levels

Due to some programming mistakes we have products with stock level 0 and 3. 3 as you know is out of stock and 0 is unlimited.

Can we filter out both 0 and 3?

Like

'filter'=> [
['filter'=> 'stock_level', 'match'=> 'neq', 'value'=> 3 ],
[ 'filter'=> 'stock_level', 'match'=> 'neq', 'value'=> 0 ],
'match'=>'or'
]

Edit. Maybe a regex?

Lexi McGee

Lexi McGee 3 points

  • 3 years ago

Answering myself

['filter' => 'stock_level', 'match'=> 'regex', 'value'=> "^[^0|^3]+$"]

Edit. That didn't do the trick. The regex seems to be matching 10 and 30 for example.

Anyone know the right regex to exclude 0 and 3 from a filter match?

^(?!3$|0$).*$ doesn't work

^[^0|^3]+$

matches 10 30 35

Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

Hello Lexi,

3 as you know is out of stock and 0 is unlimited.

It sounds like you are looking for stock_status not stock_level.

Something like this should work:

'filter' => 'stock_status',
'match' => '!in',
'value' => '0,3',