Home Forums ACF PRO acf_form + create comment + woocommerce review


acf_form + create comment + woocommerce review

  • Howdy,

    I would like to use acf_form to create a new comment. Specifically I would like to create a Woocommerce Review from an acf_form. The parent post would be set parametrically (via query_var)

    My action:

    function my_acf_save_post() {
    		$parent_post_id = get_query_var( 'parent_post_id_set_via_query_var');
    		$commentdata = array(
    			'comment_post_ID' => $parent_post_id,
    			'comment_author' => 'Bob Saget',
    			'comment_author_email' => '[email protected]',
    			'comment_author_url' => '[email protected]',
    			'comment_content' => 'Stuff Bob says',
    			'comment_type' => '', // left empty because it seems WC doesn't specify the comment_type for reviews
    			'user_id' => $current_user->ID, //passing current user ID or any predefined as per the demand
    		//Insert new comment and get the comment ID
    		$comment_id = wp_new_comment( $commentdata );
    		// Here comment_meta after comment_id is set

    // run after ACF saves the $_POST[‘acf’] data
    add_action(‘acf/save_post’, ‘my_acf_save_post’, 20);

    The ACF form:

    $acf_review_opts = array(
    	'post_id'		=> 'new_comment', // Since comments aren't 'posts,' is this right?
    	'form_attributes'	=> array('id' => 'wc_acf_review'),
    	'post_title'		=> false,
    	'field_groups'		=> array(

    Am I on the right track? If not, what am I doing wrong?

    Thanks in advance

  • What version of ACF are you using? ACF 5 has the ability to add custom fields to specific comment forms. I’m not familiar with WC reviews but it seems this would be an easier path than using ACF form. To be honest, I’m not at all sure that it’s possible to use acf_form() to create comments.

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

The topic ‘acf_form + create comment + woocommerce review’ is closed to new replies.