Fatal errors due to uncaught TypeError
-
Hi.
I was sometimes getting an error when registering for an out of stock product. Looked like this:
E_ERROR (1): Uncaught TypeError: Unsupported operand types: int + string in /wp-content/plugins/woocommerce-product-stock-alert/classes/class-woo-product-stock-alert-ajax.php:220 Stack trace: #0 /wp-includes/class-wp-hook.php(303): WOO_Product_Stock_Alert_Ajax->stock_alert_function() #1 /wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters() #2 /wp-includes/plugin.php(470): WP_Hook->do_action() #3 /wp-admin/admin-ajax.php(187): do_action() #4 {main} thrown in /wp-content/plugins/woocommerce-product-stock-alert/classes/class-woo-product-stock-alert-ajax.php on line 220
The same error occurres here as well:
E_ERROR (1): Uncaught TypeError: Unsupported operand types: string - int in /wp-content/plugins/woocommerce-product-stock-alert/classes/class-woo-product-stock-alert-admin.php:409 Stack trace: #0 /wp-includes/class-wp-hook.php(305): WOO_Product_Stock_Alert_Admin->check_product_stock_status() #1 /wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters() #2 /wp-includes/plugin.php(470): WP_Hook->do_action() #3 /wp-includes/post.php(4468): do_action() #4 /wp-includes/post.php(4570): wp_insert_post() #5 /wp-admin/includes/post.php(423): wp_update_post() #6 /wp-admin/includes/ajax-actions.php(2069): edit_post() #7 /wp-includes/class-wp-hook.php(303): wp_ajax_inline_save() #8 /wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters() #9 /wp-includes/plugin.php(470): WP_Hook->do_action() #10 /wp-admin/admin-ajax.php(187): do_action() #11 {main} thrown in /wp-content/plugins/woocommerce-product-stock-alert/classes/class-woo-product-stock-alert-admin.php on line 409
To avoid this error please cast the variable you get the number of subscribers via
get_post_meta
as integer. Sometime the DB only returns an empty string instead of an integer.So adding
$no_of_subscribers = intval($no_of_subscribers);
and
$parent_product_subscribers = intval($parent_product_subscribers);
right after you get this values from get_post_meta solves this issue.Kind regards,
iteratus
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Fatal errors due to uncaught TypeError’ is closed to new replies.