protected function read_product_data(&$product)
{
$id = $product->get_id();
if ('' === ($review_count = get_post_meta($id, '_wc_review_count', true))) {
WC_Comments::get_review_count_for_product($product);
} else {
$product->set_review_count($review_count);
}
if ('' === ($rating_counts = get_post_meta($id, '_wc_rating_count', true))) {
WC_Comments::get_rating_counts_for_product($product);
} else {
$product->set_rating_counts($rating_counts);
}
if ('' === ($average_rating = get_post_meta($id, '_wc_average_rating', true))) {
WC_Comments::get_average_rating_for_product($product);
} else {
$product->set_average_rating($average_rating);
}
$product->set_props(array('featured' => get_post_meta($id, '_featured', true), 'catalog_visibility' => get_post_meta($id, '_visibility', true), 'sku' => get_post_meta($id, '_sku', true), 'regular_price' => get_post_meta($id, '_regular_price', true), 'sale_price' => get_post_meta($id, '_sale_price', true), 'price' => get_post_meta($id, '_price', true), 'date_on_sale_from' => get_post_meta($id, '_sale_price_dates_from', true), 'date_on_sale_to' => get_post_meta($id, '_sale_price_dates_to', true), 'total_sales' => get_post_meta($id, 'total_sales', true), 'tax_status' => get_post_meta($id, '_tax_status', true), 'tax_class' => get_post_meta($id, '_tax_class', true), 'manage_stock' => get_post_meta($id, '_manage_stock', true), 'stock_quantity' => get_post_meta($id, '_stock', true), 'stock_status' => get_post_meta($id, '_stock_status', true), 'backorders' => get_post_meta($id, '_backorders', true), 'sold_individually' => get_post_meta($id, '_sold_individually', true), 'weight' => get_post_meta($id, '_weight', true), 'length' => get_post_meta($id, '_length', true), 'width' => get_post_meta($id, '_width', true), 'height' => get_post_meta($id, '_height', true), 'upsell_ids' => get_post_meta($id, '_upsell_ids', true), 'cross_sell_ids' => get_post_meta($id, '_crosssell_ids', true), 'purchase_note' => get_post_meta($id, '_purchase_note', true), 'default_attributes' => get_post_meta($id, '_default_attributes', true), 'category_ids' => $this->get_term_ids($product, 'product_cat'), 'tag_ids' => $this->get_term_ids($product, 'product_tag'), 'shipping_class_id' => current($this->get_term_ids($product, 'product_shipping_class')), 'virtual' => get_post_meta($id, '_virtual', true), 'downloadable' => get_post_meta($id, '_downloadable', true), 'gallery_image_ids' => array_filter(explode(',', get_post_meta($id, '_product_image_gallery', true))), 'download_limit' => get_post_meta($id, '_download_limit', true), 'download_expiry' => get_post_meta($id, '_download_expiry', true), 'image_id' => get_post_thumbnail_id($id)));
// Gets extra data associated with the product.
// Like button text or product URL for external products.
foreach ($product->get_extra_data_keys() as $key) {
$function = 'set_' . $key;
if (is_callable(array($product, $function))) {
$product->{$function}(get_post_meta($product->get_id(), '_' . $key, true));
}
}
}