• My client does not use categories for his WooCommerce products. This has caused a fatal error in this plugin.

    The error message is:

    [20-Nov-2024 17:15:52 UTC] PHP Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, bool given in /wp-content/plugins/official-facebook-pixel/integration/FacebookWordpressWooCommerce.php:126
    Stack trace: 0 /wp-content/plugins/official-facebook-pixel/integration/FacebookWordpressWooCommerce.php(126): count(false) 1 /wp-content/plugins/official-facebook-pixel/integration/FacebookWordpressWooCommerce.php(116): FacebookPixelPlugin\Integration\FacebookWordpressWooCommerce::getProductCategory(12076)

    I have edited the getProductCategory() function in integration/FacebookWordpressWooCommerce.php:

    private static function getProductCategory($product_id){
    $categories = get_the_terms(
    $product_id,
    'product_cat'
    );
    // return count($categories) > 0 ? $categories[0]->name : null;
    return ( is_array( $categories ) && count($categories) > 0) ? $categories[0]->name : null;
    }

    get_the_terms() returns false when there are no categories.

    BTW, the is_array($categories) check could be simplified to $categories.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Same problem here. is_array($categories) solves the problem until the next update…

    Plugin Support iodic

    (@iodic)

    Hi guys, thank you reaching out and outlining the issue. We will share this with the development team to review and address.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.