Fatal error when calling available_variation()
-
Hello,
I’ve encountered a fatal error in the current version of WPC Product Quantity Premium.
The issue occurs inwpc-product-quantity.phparound line 858:Fatal error: Uncaught Error: Call to a member function is_type() on false in
/wp-content/plugins/wpc-product-quantity-premium/wpc-product-quantity.php:858
Stack trace:
0 /wp-content/plugins/wpc-product-quantity-premium/wpc-product-quantity.php(876): WPCleverWoopq->get_quantity()
1 /wp-content/plugins/wpc-product-quantity-premium/wpc-product-quantity.php(921): WPCleverWoopq->get_type()
2 /wp-content/plugins/wpc-product-quantity-premium/wpc-product-quantity.php(1850): WPCleverWoopq->get_min()
3 /wp-includes/class-wp-hook.php(324): WPCleverWoopq->available_variation()
…The error happens when the method
available_variation()is executed in a context where the$productparameter isfalseornull, so calling$product->is_type()throws a fatal error.The plugin assumes that
$productis always an instance ofWC_Product,
but in some contexts (for example during certain AJAX calls or variation rendering),
thewoocommerce_available_variationfilter can be triggered with an invalid or empty product reference.To prevent the fatal error, a simple instance check should be added before accessing
$productmethods, e.g.:if ( ! $product instanceof WC_Product ) { return $data; }Suggested fix:
Add this validation in the following methods before using
$product:get_type()get_min()available_variation()
This ensures compatibility with all WooCommerce contexts and prevents fatal errors when
$productis not properly initialized.The page I need help with: [log in to see the link]
The topic ‘Fatal error when calling available_variation()’ is closed to new replies.