controller
controller copied to clipboard
Error with woocommerce and ACF Invalid argument supplied for foreach()
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
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') ?: [];
}