Divi WordPress Theme
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

WordPress fix Invalid argument in foreach (Woocommerce)

Discussion in 'Misc WordPress Requests' started by zanzibarwinds, Mar 26, 2018.

  1. zanzibarwinds

    Guest

    Invalid argument in foreach (Woocommerce), by zanzibarwinds

    HI

    I recently updated to WordPress (version 4.9.4). The site uses WooCommerce and when going to the Products page of the Admin UI I get this error for each product in the list:

    Warning: Invalid argument supplied for foreach() in /home/somesite/public_html/wp-content/themes/base/functions.php on line 1169

    I managed to write code to check the $price object was actually an object and this seemingly fixes the issue.

    foreach($prices as $the_price) {
    if($the_price > 0) {
    $unavailable = false;
    $price = $the_price;
    }
    }

    changed to…

    if(is_object($prices) || isset($prices)){
    foreach($prices as $the_price) {
    if($the_price > 0) {
    $unavailable = false;
    $price = $the_price;
    }
    }
    }

    The problem is I am editing a WooCommerce function in the functions.php file and doubt this is the way to go, I’d rather find out if any one else encountered this issue and if they found a fix for it.

    Invalid argument in foreach (Woocommerce)
     
    #1

Share This Page

Monarch Social Sharing Plugin