3
votes

Ok I'll try and ask this in a way that will not confuse everyone with my confusion

I am trying to make a front-end form for WooCommerce so customers can make a product from the front-end. I have all the other parts I want to implement so far working ie. Title, content and price all posted in the correct post type. But can't get it to post to a product category

WooCommerce categories is a custom-Taxonomy named product_cat <--almost 100% sure.

product_cat children are Terms, I have three --> Base, Designs and User Designs

I want all posts from this form to automatically be under User Designs. This is what I have now

$post_information = array(
        'post_title' => esc_attr(strip_tags($_POST['postTitle'])),
        'post_content' => esc_attr(strip_tags($_POST['postContent'])),
        'post_type' => 'product',
        'post_status' => 'publish',


    );

$post_id = wp_insert_post($post_information);
  update_post_meta( $post_id, '_regular_price', strip_tags($_POST['_regular_price'] ) ) ;


    if($post_id)
    {
        wp_redirect(home_url());
        exit;
    }

};

I have tried many variations to set terms like

 wp_set_object_terms($post_id, 'designs', 'product_cat', false);
 wp_set_post_terms($post_id, 'designs', 'product_cat', false);
 wp_set_object_terms($post_id, $designs ,'product_cat');
 wp_set_post_terms( $post_id, $designs, 'product_cat', true );
 wp_set_object_terms($post_id, $base, 'product_cat');           

No go, I know I'm missing something but I have no idea what. I've been looking at my screen so long my eyes are crossing,

Any help will be greatly appreciated thanks in advance

1

1 Answers

0
votes

Use the following:

wp_set_post_terms( $product_id, '343', 'product_cat');

Where $product_id is the post_id of the product you're making, and 343 is the taxonomy id (you can get it from one of the taxonomy tables)