Please submit a private ticket if you need to share sensitive information, such as license details and admin credentials.

Okay
  Public Ticket #4515278
Fatal error when calling available_variation()
Open

Comments

  • Marc started the conversation

    Hello,

    I’ve encountered a fatal error in the current version of WPC Product Quantity Premium.
    The issue occurs in wpc-product-quantity.php around 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 $product parameter is false or null, so calling $product->is_type() throws a fatal error.

    The plugin assumes that $product is always an instance of WC_Product,
    but in some contexts (for example during certain AJAX calls or variation rendering),
    the woocommerce_available_variation filter can be triggered with an invalid or empty product reference.

    To prevent the fatal error, a simple instance check should be added before accessing $product methods, 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 $product is not properly initialized.

  •  1,561
    Dustin replied

    Hi Marc,

    Thanks for letting us know about this issue!

    I have fixed it and released the updated version 5.1.4.

    Best regards,
    Dustin