Check if product is object before adding to array. Prevents non-object fatal errors
This commit is contained in:
parent
3b547c4218
commit
9c9b494d0f
|
@ -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 ) );
|
||||
|
|
Loading…
Reference in New Issue