Hi jarvis,
thanks a lot for your input! You are right for vanilla Woocommerce Reviews. I tried it myself and it works. The problem is, I am already using a plugin that enhances the Woocommerce Reviews and I try to extend this plugin with those custom fields. The method you explain doesn’t work with this plugin. Only in the backend but not in the frontend form.
I worked on this issue and managed to get a bit further.
(with help of this artivle https://medium.com/techcompose/how-to-add-advanced-custom-fields-acf-to-a-frontend-form-2b89c8cfdcee)
<?php
$new_post= array(
‘post_id’ => ‘new_post’,
‘field_groups’ => array(21112),
‘post_title’ => false,
‘post_content’ => false,
‘form’ => false
);
acf_form( $new_post);
?>
This way the I do not get an additional submit button and the original submit button still works. I can submit reviews this way. The only problem remaining. Only the original Inputs get saved. The Inputs of the new custom fields do not.
I assume I am still doing something wrong in the code that goes into functions.php
add_filter(‘acf/pre_save_post’, ‘save_post_from_frontend’);
function save_post_from_frontend( $post_id) {
//Check if user loggin or can publish post
if( ! ( is_user_logged_in() || current_user_can(‘publish_posts’) ) ) {
return;
}
// check if this is to be a new post
if( $post_id!= ‘new_post’) {
return $post_id;
}
$post= array(
‘post_type’ => ‘w2rr_review’, // Your post type ( post, page, custom post type )
‘post_status’ => ‘publish’, // (publish, draft, private, etc.)
);
// insert the post
$post_id= wp_insert_post( $post);
// Save the fields to the post
do_action( ‘acf/save_post’, $post_id);
return $post_id;
}