JivoyRoman2019-06-10 08:02:11
JivoyRoman, 2019-06-10 08:02:11

Advanced Custom Fields - How to validate and display the relevant fields?

Collected the manager part of data entry based on fields from Advanced Custom Fields. But there is a problem with displaying data on the site for users.
There are 4 kinds of goods; Linoleum, tiles, carpets, carpet.
Each product has its own information.
Depending on the choice of the manager, the necessary fields for filling open.
The manager chooses Linoleum - fields are opened for him to fill in the data on linoleum.
Selects Tile - Tile Data.
I did this:
Displaying fields in the admin panel according to conditional logic.

Создал первое поле (тип селект)5cfddf882674d520766215.jpeg

filled it out
типами товаров5cfddfc8dea5f437794010.jpeg

And tied all the other fields
условной логикой от содержимого этого поля5cfde00ba8e75108936979.jpeg
It turns out that when the manager wants to fill in the characteristics of the product, he will first select the type, and depending on this, he will see the corresponding. fields to fill.
But now how to output it to users?
To display both the item (label) of the field and the value of the field, depending on whether the field is filled in or not.
In the admin panel of the goods, the manager will select - Type of goods Linoleum, but will fill in only a couple of fields. The rest will be empty.
The user needs to display the field name, the field value. If the field value is empty, then the field name is not displayed. No code option:
add_action( 'woocommerce_product_meta_start', 'my_custom_action' );
function my_custom_action() {
  if ('Коммерческий' == get_the_field('type') ) {
echo 'Вид: ' . the_field('linoleum_vid');
echo '<p>';

check all field values. It is necessary that it be possible to check for an empty / non-empty value.
Сделал набросок полей5cfde14b7e2d0841275725.jpeg

Can you tell me how to write a code so that all fields are covered in it, checked for the type of product / category (type_product_or_category), for completeness and displayed together with the item name and its value? For me it seems complicated.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Mr Crabbz, 2019-06-10

Get field objects and parse a regular array of values. Everything is simple.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question