Check if product is object before adding to array. Prevents non-object fatal errors

This commit is contained in:
Nathaniel Schweinberg 2015-03-28 09:09:43 -05:00
parent 3b547c4218
commit 9c9b494d0f
1 changed files with 6 additions and 2 deletions

View File

@ -103,7 +103,9 @@ class WC_Meta_Box_Coupon_Data {
foreach ( $product_ids as $product_id ) {
$product = wc_get_product( $product_id );
$json_ids[ $product_id ] = wp_kses_post( $product->get_formatted_name() );
if( is_object( $product ) ) {
$json_ids[ $product_id ] = wp_kses_post( $product->get_formatted_name() );
}
}
echo esc_attr( json_encode( $json_ids ) );
@ -119,7 +121,9 @@ class WC_Meta_Box_Coupon_Data {
foreach ( $product_ids as $product_id ) {
$product = wc_get_product( $product_id );
$json_ids[ $product_id ] = wp_kses_post( $product->get_formatted_name() );
if( is_object( product ) ) {
$json_ids[ $product_id ] = wp_kses_post( $product->get_formatted_name() );
}
}
echo esc_attr( json_encode( $json_ids ) );