Check if product exists to avoid fatal errors on emails order schema markup, closes #11459

This commit is contained in:
Claudio Sanches 2016-07-19 08:21:06 -03:00
parent 14eeee15ee
commit a8becb24ba
1 changed files with 13 additions and 10 deletions

View File

@ -289,16 +289,23 @@ class WC_Emails {
continue;
}
$product = apply_filters( 'woocommerce_order_item_product', $order->get_product_from_item( $item ), $item );
$is_visible = $product && $product->is_visible();
$product = apply_filters( 'woocommerce_order_item_product', $order->get_product_from_item( $item ), $item );
$product_exists = is_object( $product );
$is_visible = $product_exists && $product->is_visible();
$item_offered = array(
'@type' => 'Product',
'name' => apply_filters( 'woocommerce_order_item_name', $item['name'], $item, $is_visible )
'name' => apply_filters( 'woocommerce_order_item_name', $item['name'], $item, $is_visible ),
);
if ( $sku = $product->get_sku() ) {
$item_offered['sku'] = $sku;
if ( $product_exists ) {
if ( $sku = $product->get_sku() ) {
$item_offered['sku'] = $sku;
}
if ( $image_id = $product->get_image_id() ) {
$item_offered['image'] = wp_get_attachment_image_url( $image_id, 'thumbnail' );
}
}
if ( $is_visible ) {
@ -307,10 +314,6 @@ class WC_Emails {
$item_offered['url'] = get_home_url();
}
if ( $image_id = $product->get_image_id() ) {
$item_offered['image'] = wp_get_attachment_image_url( $image_id, 'thumbnail' );
}
$accepted_offer = (object) array(
'@type' => 'Offer',
'itemOffered' => $item_offered,
@ -320,7 +323,7 @@ class WC_Emails {
'@type' => 'QuantitativeValue',
'value' => apply_filters( 'woocommerce_email_order_item_quantity', $item['qty'], $item )
),
'url' => get_home_url(),
'url' => get_home_url(),
);
$accepted_offers[] = $accepted_offer;