WC_Product_Data_Store_CPT::create PHP Method

create() public method

Method to create a new product in the database.
public create ( &$product )
    public function create(&$product)
    {
        $product->set_date_created(current_time('timestamp'));
        $id = wp_insert_post(apply_filters('woocommerce_new_product_data', array('post_type' => 'product', 'post_status' => $product->get_status() ? $product->get_status() : 'publish', 'post_author' => get_current_user_id(), 'post_title' => $product->get_name() ? $product->get_name() : __('Product', 'woocommerce'), 'post_content' => $product->get_description(), 'post_excerpt' => $product->get_short_description(), 'post_parent' => $product->get_parent_id(), 'comment_status' => $product->get_reviews_allowed() ? 'open' : 'closed', 'ping_status' => 'closed', 'menu_order' => $product->get_menu_order(), 'post_date' => date('Y-m-d H:i:s', $product->get_date_created()), 'post_date_gmt' => get_gmt_from_date(date('Y-m-d H:i:s', $product->get_date_created())))), true);
        if ($id && !is_wp_error($id)) {
            $product->set_id($id);
            $this->update_post_meta($product);
            $this->update_terms($product);
            $this->update_attributes($product);
            $this->update_downloads($product);
            $product->save_meta_data();
            do_action('woocommerce_new_product', $id);
            $product->apply_changes();
            $this->update_version_and_type($product);
            $this->update_term_counts($product);
            $this->clear_caches($product);
        }
    }