Today, I will show you a small snippet on how to change the order of WooCommerce Review form fields. In this large online stores industry, several times we need to change the basic WooCommerce fields order or something else that can fit our business model.
For example, in my personal experience, I have changed the order of review form fields in a single product page on WooCommerce. By default, first is shown the Review Message field and then the User Name and Email Fields, like in the image:
Now, sometimes we need to position the “Your Review” field after the “Name” and “Email” fields. For doing so, just copy and paste this code in your functions.php file on Main Theme or Child Theme
add_filter( 'comment_form_fields', 'codeless_woo_comment_form_fields', 9 ); function codeless_woo_comment_form_fields( $fields ){ if( function_exists('is_product') && is_product() ){ $comment_field = $fields['comment']; unset( $fields['comment'] ); $fields['comment'] = $comment_field; } return $fields; }
We highly recommend you to use a premium WordPress Theme when you create a professional online store with WooCommerce. Our suggestion is to use June Theme. It's professional, beautiful, awesome UX to make your online store converts more and most importantly, awesome support by a specialized team ( Codeless Team ).
Ludjon, who co-founded Codeless, possesses a deep passion for technology and the web. With over a decade of experience in constructing websites and developing widely-used WordPress themes, Ludjon has established himself as an accomplished expert in the field.
Comments
Nice way,
I suggest this way:
add_filter( 'comment_form_fields', 'codeless_woo_comment_form_fields', 9 );
function codeless_woo_comment_form_fields( $fields ){
if( function_exists('is_product') && is_product() ){
$fields_order=[
'author' => null,
'email' => null,
'comment'=> null,
'cookies' => null
];
$fields = array_replace_recursive($fields_order, $fields);
}
return $fields;
}