• Resolved iteratus

    (@iteratus)


    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

    • This topic was modified 2 years, 4 months ago by iteratus.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author MultiVendorX

    (@wcmp)

    Hi9 @iteratus, thanks for explaining the issue. But can you please explain how to recreate this on our end, as we are not able to generate the same?

    Thread Starter iteratus

    (@iteratus)

    I’m not quite sure how to reproduce it on a clean setup. I use of course a massive punch of plugins and I’m not sure how they interfer. But it seems to be quite understandable when I think about it:
    – I installed your plugin long after the initial setup but probably befor our final products import
    – The error occurrs only the first time I register for a product where obviously no db entry is available yet, therefore the value being returned seems to be an empty string.
    – Since the script ended with a fatal error it was not able to update the db anymore, so the error keeps occurring
    – As soon as I typecasted the variable, the empty string was converted into a valud integer (0 in the first case) and the following addition worked without an error.
    – From this time on the product registering worked as expected for this product, even when I disabled the typecast again. So it seems that the script updated the DB correctly and the get_post_meta then returns a zero string ‘0’ which then gets converted by PHP on the fly.

    I usse PHP 8.0.12 as FPM on nginx

    Besides that, I’m not quite sure how to help you more specifically.

    Plugin Author MultiVendorX

    (@wcmp)

    @iteratus, our team is working on a fix. Hopefully by tomorrow we can release an update.

    Plugin Author MultiVendorX

    (@wcmp)

    Hi @iteratus, this issue has been fixed in our update.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Fatal errors due to uncaught TypeError’ is closed to new replies.