Ensure product exists in API call

Fixes #6288
This commit is contained in:
Mike Jolley 2014-09-17 17:23:02 +01:00
parent 815a627edf
commit a092fce0c2
1 changed files with 7 additions and 5 deletions

View File

@ -396,11 +396,13 @@ class WC_API_Reports extends WC_API_Resource {
$product = wc_get_product( $top_seller->product_id );
$top_sellers_data[] = array(
'title' => $product->get_title(),
'product_id' => $top_seller->product_id,
'quantity' => $top_seller->order_item_qty,
);
if ( $product ) {
$top_sellers_data[] = array(
'title' => $product->get_title(),
'product_id' => $top_seller->product_id,
'quantity' => $top_seller->order_item_qty,
);
}
}
return array( 'top_sellers' => apply_filters( 'woocommerce_api_report_response', $top_sellers_data, $this->report, $fields, $this->server ) );