fix BadMethodCallException

receiving lines like this in the php error log:

Fatal error: Uncaught exception 'BadMethodCallException' with message 'Call to a member function get_formatted_name() on a non-object (boolean)' in /var/www/example.com/htdocs/wp-content/plugins/woocommerce/includes/admin/meta-boxes/class-wc-meta-box-product-data.php:484\nStack trace:\n#0 /var/www/example.com/htdocs/wp-admin/includes/template.php(1044): WC_Meta_Box_Product_Data::output()\n#1 /var/www/example.com/htdocs/wp-admin/edit-form-advanced.php(600): do_meta_boxes()\n#2 /var/www/example.com/htdocs/wp-admin/post.php(209): include()\n#3 {main}

The error resulted in a WSOD when trying to edit some products.
This commit is contained in:
pjv 2015-02-22 09:01:37 -07:00
parent b25e51dbe6
commit 1cdc3174ca
1 changed files with 6 additions and 2 deletions

View File

@ -481,7 +481,9 @@ class WC_Meta_Box_Product_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 ) );
@ -494,7 +496,9 @@ class WC_Meta_Box_Product_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 ) );