Skip to content
Advertisement

How to filter an object array in php by value of a parameter?

I’m new to php and I’m trying to filter an array of fields so that it only contains fields that have required property.

In javascript I would do it simply by:

JavaScript

but I have no idea how to do it in php.

I’m quite new to php syntax, and have been unsuccessful with implementing array_filter. I’m trying to edit woocommerce template to only show required fields. This is what each field has:

JavaScript

My $fields array should be only objects that have required = true

JavaScript

Advertisement

Answer

I managed to solve the issue by overriding the woocommerce checkout template and added custom fields and removed the ones I didn’t need. The project is closed so I cannot share any code of how I did it, but I’m closing this issue.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement