Join our new community forum for support & discussion

Join Now

Home Support Extensions Reviews add fields to review form

add fields to review form

  • Author
    Posts
  • frshminds

    i need to add fields to the review form. i’m using these 2 hooks but the fields do not show up in the form:

    add_filter( 'hivepress/v1/models/review/fields', function ($fields, $model) {
    
                $fields['text']['label'] = esc_html__('Review', 'hivepress-reviews');
    
                $fields['rating_professionalism'] = [
                    'label' => esc_html__('Professionalism', 'hivepress-reviews'),
                    'type' => 'rating',
                    'required' => true,
                    '_alias'   => 'rating_professionalism',
                    '_external' => true
                ];
    
                $fields['rating_punctuality'] = [
                    'label' => esc_html__('Punctuality', 'hivepress-reviews'),
                    'type' => 'rating',
                    'required' => true,
                    '_alias' => 'rating_punctuality',
                    '_external' => true
                ];
    
                $fields['rating_cleanliness'] = [
                    'label' => esc_html__('Cleanliness', 'hivepress-reviews'),
                    'type' => 'rating',
                    'required' => true,
                    '_alias' => 'rating_cleanliness',
                    '_external' => true
                ];
    
                return $fields;
    
            }, 1000, 2);
    
            add_filter('hivepress/v1/forms/review_submit', function ($form_args, $form) {
    
                unset($form_args['fields']['rating']);
    
                $form_args['fields'] = array(
    
                    'rating_professionalism' => array(
                        '_order' => 30
                    ),
    
                    'rating_punctuality' => array(
                        '_order' => 40
                    ),
    
                    'rating_cleanliness' => array(
                        '_order' => 50
                    ),
    
                    'text' => array(
                        '_order' => 60
                    ),
    
                    'listing' => array(
                        'display_type' => 'hidden',
                    )
    
                );
    
                return $form_args;
    
            }, 1000, 2);
    frshminds

    it looks like i have to add the fields also in the component

    ihor developer

    Please try using these hooks:

    hivepress/v1/models/review
    hivepress/v1/forms/review_submit

    And add fields this way https://www.youtube.com/watch?v=K99tO0-42nE&ab_channel=HivePress Both hooks accept an array where the fields parameter can be changed. If you want the field value to be saved as a meta then also the _external => true, flag is required for a field.

    frshminds

    thanks. that seems to work.

    do you have any guidance on how to add different fields based on the listing category? thanks for your help!

    frshminds

    i’ve used conditionals in those hooks and it seems to work

    ihor developer

    Yes, if there’s a listing object (HivePress model) then you can get category IDs this way:

    $listing->get_categories__id()

Viewing 6 posts - 1 through 6 (of 6 total)

New Reply

This forum has been archived and is no longer accepting new posts or replies. Please join our new community forum for support & discussion.