Uncaught Error: Call to a member function get_type() on bool - BackinStock Notifier Wordpress Plugin
Zaw Htut Win

Zaw Htut Win @zawhtutwin

About: Developer, Code Poet

Location:
Yangon
Joined:
Jun 4, 2021

Uncaught Error: Call to a member function get_type() on bool - BackinStock Notifier Wordpress Plugin

Publish Date: Jan 12 '24
0 0

It's because of the following code, the error was being thrown.

/plugins/backinstocknotifier/backinstocknotifier.php

            $product = wc_get_product($post_id);  
            if($product->get_type() == 'variable') {
                // the rest of the code
            }
Enter fullscreen mode Exit fullscreen mode

It doesn't check the post is the product or not, so when the post is not the product, the plugin will throw error.
So we can correct the code such as,

            $product = wc_get_product($post_id);  
            if(isset($product) && $product === false){return;} // exit the function if the post_id not corresponding to product
            if($product->get_type() == 'variable') {
                // the rest of the code
            }
Enter fullscreen mode Exit fullscreen mode

Comments 0 total

    Add comment