controller icon indicating copy to clipboard operation
controller copied to clipboard

Error with woocommerce and ACF Invalid argument supplied for foreach()

Open voyou-sbeaulieu opened this issue 5 years ago • 2 comments

Hi, it's look's like a problem between Woocommerce template page and controller action.

Not really sure why but on the shop page from woocommerce exemple.com/shop

We use this root branch to use blade templating from woocommerce: https://github.com/roots/sage-woocommerce

It's working as expected on the product page. only the archive-product.php seems to have this problem and we can't figure out why..

Here the error report :

Whoops\Exception\ErrorException thrown with message "Invalid argument supplied for foreach()"

Stacktrace:
#18 Whoops\Exception\ErrorException in /var/www/html/web/app/plugins/advanced-custom-fields-pro/includes/acf-meta-functions.php:95
#17 Whoops\Run:handleError in /var/www/html/web/app/plugins/advanced-custom-fields-pro/includes/acf-meta-functions.php:95
#16 acf_get_meta in /var/www/html/web/app/plugins/advanced-custom-fields-pro/includes/api/api-template.php:316
#15 get_field_objects in /var/www/html/web/app/plugins/advanced-custom-fields-pro/includes/api/api-template.php:269
#14 get_fields in /var/www/html/web/app/themes/wp-innovaspa/vendor/soberwp/controller/src/Module/Acf.php:79
#13 Sober\Controller\Module\Acf:setData in /var/www/html/web/app/themes/wp-innovaspa/vendor/soberwp/controller/src/Controller.php:143
#12 Sober\Controller\Controller:__setDatafromModuleAcf in /var/www/html/web/app/themes/wp-innovaspa/vendor/soberwp/controller/src/Controller.php:88
#11 Sober\Controller\Controller:__setData in /var/www/html/web/app/themes/wp-innovaspa/vendor/soberwp/controller/controller.php:69
#10 Sober\Controller\{closure} in /var/www/html/web/wp/wp-includes/class-wp-hook.php:286
#9 WP_Hook:apply_filters in /var/www/html/web/wp/wp-includes/plugin.php:208
#8 apply_filters in /var/www/html/web/app/themes/wp-innovaspa/app/filters.php:60
#7 App\{closure} in [internal]:0
#6 array_reduce in /var/www/html/web/app/themes/wp-innovaspa/vendor/illuminate/support/Collection.php:1313
#5 Illuminate\Support\Collection:reduce in /var/www/html/web/app/themes/wp-innovaspa/app/filters.php:61
#4 App\{closure} in /var/www/html/web/wp/wp-includes/class-wp-hook.php:286
#3 WP_Hook:apply_filters in /var/www/html/web/wp/wp-includes/plugin.php:208
#2 apply_filters in /var/www/html/web/wp/wp-includes/template-loader.php:76
#1 require_once in /var/www/html/web/wp/wp-blog-header.php:19
#0 require in /var/www/html/web/index.php:5

voyou-sbeaulieu avatar May 27 '19 16:05 voyou-sbeaulieu

Look like this is related to this issue : https://github.com/soberwp/controller/issues/114

and @mmirus do fix my problem. Is this patch live yet?

<?php

declare(strict_types=1);

namespace App\Controllers;

use Sober\Controller\Controller;

class App extends Controller
{
    protected $acf = false;

    public function __construct()
    {
        if (acf_get_valid_post_id(get_queried_object())) {
            $this->acf = true;
        }
    }

    public function acfOptions() : array
    {
        return get_fields('options') ?: [];
    }

voyou-sbeaulieu avatar May 27 '19 17:05 voyou-sbeaulieu

Pushed bee62f based on the above, not yet tagged but should remove the issue.

(Little late I know)

darrenjacoby avatar May 27 '21 14:05 darrenjacoby