Dropdown list that loads Product Comment Form

I am trying to create a dropdown of all product in my WooCommerce store and based on the selected product I want to display that products comment form.

I want to create a page with this code in it.

This code is what I am using so far,

2 Problems with this code (1) not allowing me to select to show only comment form and title. (2) always loads the same product as default even after changing selection.

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

$the_query = new WP_Query( $args );
echo ‘<form action=”” method=”get”>’;
echo ‘<select name=”product_id” onchange=”this.form.submit()” >’;
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>’;

echo ‘</form>’;

}

Read more here:: Dropdown list that loads Product Comment Form

Leave a Reply

Your email address will not be published. Required fields are marked *