Skip Navigation

[Resolved] Output Review form based on Product Dropdown

This support ticket is created 4 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Tagged: 

This topic contains 14 replies, has 3 voices.

Last updated by Beda 4 years, 9 months ago.

Assisted by: Beda.

Author
Posts
#1290667

Tell us what you are trying to do?
I want to create a page in which a customer can select any product from a dropdown and once selected it will display the following [wpv-post-title][wpv-woo-single-products-rating][wpv-woo-reviews] based on the product selected from dropdown.

Is there any documentation that you are following?
No

Is there a similar example that we can see?
Not sure

#1290691

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Paul,

Thank you for contacting our support forum.

You aren't able to have a dropdown list with the post title, you can filter posts by their various custom fields and taxonomy but not by the title in a dropdown.

The only way to filter the title is with the use of a custom search box.

So perhaps you can filter the posts by one of its attributes and still display the same data that you want to.

Thanks,
Shane

#1290709

Hello,

Okay, so I created a taxonomy for Color which represents the product title exactly.

I set up a view content selection: products

search and pagination:

[wpv-filter-start hide="false"]
[wpv-filter-controls]
<div class="form-group">
<label>[wpml-string context="wpv-views"]Product Color[/wpml-string]</label>
[wpv-control-post-taxonomy taxonomy="pa_color" type="select" url_param="wpv-pa_color"]
</div>
[/wpv-filter-controls]
[wpv-filter-end]

Loop:

[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->
<wpv-loop>[wpv-post-title][wpv-woo-single-products-rating][wpv-woo-reviews]
</wpv-loop>[wpv-woo-reviews]
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-items-found]
[wpml-string context="wpv-views"]No items found[/wpml-string]
[/wpv-no-items-found]
[wpv-layout-end]

But it isn't working. Please, can you check?

hidden link

#1290729

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Paul,

So the product title does work.

[wpv-woo-single-products-rating] This shortcode will work on your view, but based on our documentation this one won't [wpv-woo-reviews]

The [wpv-woo-reviews] is meant to be used on a single product template.

Also do any of these products have ratings that you are displaying ?

Thanks,
Shane

#1290751

Hi Shane,

This is what I am trying to do.

Product dropdown to show review form based on selection.

Is it possible to do this and if so how?

For example, if someone selected Color: Aquila I want to show the review form for that product.

#1290759

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Paul,

Thank you for the clarity.

In this case no this is not possible, since the reviews form is in this shortcode https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-woo-display-tabs

And this shortcode only works on the single product pages, you will need to write some custom code in order to get the form to be in your view.

An alternative is that you can list the products and have the users click to the single product where they can post the review there.

Thanks,
Shane

#1290765

Hello Shane,

Can anyone in your team help me with the custom code? Can you give me some more insight, I know a bit of PHP so maybe I can piece it together.

This would also be a great addition to your software and documentation.

We are trying to build a page that we can send specific users to leave a review using a dropdown and not the other way.

#1290797

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Paul,

Actually we don't offer custom coding services, but what we do offer is that we have a list of contractors who can provide this service for you.

It's mainly because this will require the use of the woocommerce api in order to load the form here in views.

What I suggest doing is to contact one of our registered contractors for advice on how to implement this one.
https://toolset.com/contractors/

Thanks,
Shane

#1292057

I dont think that I need a contractor. I dont think we need to access the API for this.

I think all we need it just a bit more knowledge about how to create the dropdown and display the product comment form based on the dropdown selection using ajax.

Which can be achieved through this code

<?php comments_template(); ?> 

No API necessary.

I have it working but does not load on selection here hidden link

and the code I used is this.

<?php
/**
 * New custom code snippet (replace this with snippet description).
 */

toolset_snippet_security_check() or die( 'Direct access is not allowed' );

// Put the code of your snippet below this comment.

function get_custom_product_list() {



$args = array(
'post_type' => 'product',
'posts_per_page' => -1,
'post_status' => 'publish',
);

  
$the_query = new WP_Query( $args );
echo '<select name="product_id" >';
echo '<option value="">'.__("Select product").'</option>';
if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) {
$the_query->the_post();
echo '<option value="'.get_the_ID().'">'.get_the_title().'</option>';
}
}
echo '</select>';
 
} 
add_shortcode( 'product_list', 'get_custom_product_list' );
#1292099

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Paul,

I see what you are trying to do, however remember this code here.
<?php comments_template(); ?>

The context under which this is used is on a single post NOT a list of posts. In order for this to work in a list of posts, you will need to somehow create a function that will load the comment form that is specific to the ID of the post that is selected from your dropdown.

At the moment i'm not seeing a hook on wordpress that can do this, which is why I believe a complete custom solution is required.

Thanks,
Shane

#1292101

Please get me a more experienced Support, please.

There are probably 1 million ways to do this.

I think we need someone with more experience and knowledge to help solve my issue.

#1292103

I was able to accomplish with the code above to get all the product data from dropdown for 1 product. I am not experienced in javascript or Ajax so I am not able to get it to work properly. I am sure I can use custom css or php code to remove parts of data that I do not want or need.

You keep giving me dead-ends. Please allow a support staff with more experience and knowledge to take over my concern.

#1292815

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Paul,

I will be assigning this ticket to one of our 2nd tier supporters for further clarification.

Thanks,
Shane

#1293041

Thank you, Shane.

New threads created by Beda and linked to this one are listed below:

https://toolset.com/forums/topic/custom-woocommerce-reviews-and-comments-in-loop/

#1293493

Hello, I am Beda, as Shane already informed you he asked me to help you out here.

I see you want to "Output Review form based on Product Dropdown".
According to your opening comment https://toolset.com/forums/topic/output-review-form-based-on-product-dropdown/#post-1290667, you want to create a page in which a customer can select any product from a dropdown and once selected it will display the Post Title, The Product Rating and The Product Reviews for the Product selected.

For me, that sounds like what we call a "Custom Search", or also known as "Custom Queries", "Front end search", etc.
You want a list of information related to the item selected in the DropDown (your search input).

Now, as Shane points out, Toolset Views would be the tool to create this, however, Toolset Views does not allow such searches by native Post Data, which amongst other, is Post Title, Author, ID, etc. It, however, allows you to search products matching certain Custom Fields (hence, reviews and ratings, if stored as Post meta, can be used in such filters).

To have a DropDown of custom fields to find products matching those values you can follow this DOC:
https://toolset.com/learn/create-an-ecommerce-wordpress-site/search-filter-and-results/

To add a Custom Search for the Post Title you have 2 options:
1. Either you store the actual post title in an additional Toolset Types Single Line field for each product (and use that field in the search)
2. Or, you can create a custom HTML Selector populated with the Titles of the Products (you can even use a View to populate this select Field) and then by adding a Query Filter to the View, make the view listen to the URL argument passed in the Select Input, so that when a user selects a specific title the URL is updated with the new search parameters and shows those results matching the post title chosen (query filters can have filters by title, front end search not).
I elaborate on this technique here:
https://toolset.com/forums/topic/two-dropdown-search-options-on-a-custom-search/

As mentioned in all the related tickets this is not something natively possible, and hence, to have it implemented directly in Views, you'd have to ask for this here https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/
This also would apply for reccommendations like https://toolset.com/forums/topic/output-review-form-based-on-product-dropdown/#post-1290765 🙂

I see you then followed above suggestion #1 (just using a Taxonomy instead of a field, which is not wrong a all, it's a choice of how you administrate the data).
https://toolset.com/forums/topic/output-review-form-based-on-product-dropdown/#post-1290709

That seemed to not work as expected, however, that was not related anymore to the search, however to the display of the review form which is, when using that particular WooCommerce Views ShortCode, possible only on single product templates:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-woo-reviews

https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-woo-single-products-rating instead can be used on the lists.

Related to your comment here https://toolset.com/forums/topic/output-review-form-based-on-product-dropdown/#post-1292057, you mention to not use an API, but note that comments_template() is a method of an API; the WordPress API, actually, and that method will not work, just as the Toolset ShortCode for the exact same reason does not work, on lists of posts - but only on single posts.
Please consult the API DOC here:
https://developer.wordpress.org/reference/functions/comments_template/
(Will not display the comments template if not on single post or page, or if the post does not have comments.)

It's the WordPress Core, that does not allow that, and Toolset cannot help to change this.
I've tried to build a comments section in past (as a Layouts Custom Cell, actually) - and it does not work great on a post list.
I renounced to that and used Toolset Forms instead.

That won't help you here, as you need the specific WooCommerce Review mechanism, not just WordPress Comments.
To do this you need Custom Code that hooks in WooCommerce's and if required WordPress's API so to return the comments and reviews forms you need.
Those are by default only usable on single products.
You can see that people are actually struggling with this as well not using Toolset:
https://wordpress.org/support/topic/how-to-display-review-count-next-to-star-rating/#post-9524347

However, Toolset Support cannot help with such a Custom Code. This is elaborated here:
https://toolset.com/toolset-support-policy/

What we can help you with is build the things you can build with Toolset, we can also give ideas and suggest solutions or workarounds.

Hence, I would like to split this ticket in 2.
1. The ticket here we keep solely about "how to have a Front End Search (Select) by data like Post Title or Product data".
I can help you with this if more details are needed than shared above on the topic already
2. In another ticket, we can explore ways how to display and let users review a product on a Views that display such products.
One will need to analyse, where WooCommerce Stores that information, how it is displayed, and how we could gather it from users.
Please, can you elaborate precisely which data needs to be displayed and which you want to edit, here:
https://toolset.com/forums/topic/custom-woocommerce-reviews-and-comments-in-loop/

Possibly, we could use a Toolset Form, that lets you write a review, then apply a Custom Code to update the Product Reviews (comments).
There are some custom code samples online doing that already: https://wordpress.stackexchange.com/questions/114413/how-to-place-comments-template-outside-the-loop
Now, for example, if you use a view, you could try returning that in a ShortCode and instead of the global post use a Toolset ShortCode to populate the ID of the comments form in the custom code above shared. ('post_id' => $postid, here use a Toolset Post ID ShortCode instead of global post id.)

I cannot write this code for you, but I can help analyse it if it does not work and give tips where to look next, if we can handle this in a separate new ticket, you may mention that I asked you to open one, so it gets assigned to me later.

Concluding, we will handle anything towards display or input of WooCommerce Review/Comment here https://toolset.com/forums/topic/custom-woocommerce-reviews-and-comments-in-loop/, and anything related to search of that data we will continue to proceed in this very ticket here.

Please let me know if with above details you are able to create the required custom searches, and if possible, could you add the required details on the other ticket related to display of reviews in loops?

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.