• I’m working to debug a problem I’m having with the subscriptions plugin. So I’ve enabled wordpress debugging. This came up in my log overnight.

    [22-Nov-2016 09:36:32 UTC] PHP Warning: Invalid argument supplied for foreach() in /home/xxxx/public_html/wp-content/plugins/woocommerce/includes/wc-template-functions.php on line 211

Viewing 7 replies - 1 through 7 (of 7 total)
  • My line 211 doesn’t have a foreach(), are you using the latest version of WC? I’ve got 2.6.8.

    Thread Starter derekakelly

    (@derekakelly)

    Here is the code directly from my website

    function wc_body_class( $classes ) {
    	$classes = (array) $classes;
    
    	if ( is_woocommerce() ) {
    		$classes[] = 'woocommerce';
    		$classes[] = 'woocommerce-page';
    	}
    
    	elseif ( is_checkout() ) {
    		$classes[] = 'woocommerce-checkout';
    		$classes[] = 'woocommerce-page';
    	}
    
    	elseif ( is_cart() ) {
    		$classes[] = 'woocommerce-cart';
    		$classes[] = 'woocommerce-page';
    	}
    
    	elseif ( is_account_page() ) {
    		$classes[] = 'woocommerce-account';
    		$classes[] = 'woocommerce-page';   <--------- line 211
    	}
    
    	if ( is_store_notice_showing() ) {
    		$classes[] = 'woocommerce-demo-store';
    	}
    
    	foreach ( WC()->query->query_vars as $key => $value ) {
    		if ( is_wc_endpoint_url( $key ) ) {
    			$classes[] = 'woocommerce-' . sanitize_html_class( $key );
    		}
    	}
    
    	return array_unique( $classes );
    }

    Looks like what I have, but I wonder if you have an older version of WooCommerce there could be a change somewhere else. Do you have v 2.6.8, if not, consider updating.

    Thread Starter derekakelly

    (@derekakelly)

    @lorro
    Yes I am on the latest WooCommerce, 2.6.8

    I’ve downloaded a fresh copy of WooCommerce 2.6.8, and line 211 in wc-template-functions.php reads:

    
        $classes[] = 'woocommerce-page';
    

    there is a foreach() on line 218.
    Sorry to labour the point but if some files in your install are not 2.6.8 then maybe your install is incomplete and that could be a pointer to the problem.

    Thread Starter derekakelly

    (@derekakelly)

    @lorro

    I think you may have missed how i put that reply together. I just copied the whole section and pointed out my 211 line with an arrow i typed in <—–

    $classes[] = 'woocommerce-page'; <--------- line 211

    I put the whole function in because i wanted to show how it’s followed up shortly thereafter by
    foreach ( WC()->query->query_vars as $key => $value ) {

    Yes but the first post said the foreach() was on line 211, whereas the foreach() is currently on 218. So the file must have changed since the error message was created. Therefore other WooCommerce files could have changed also. So if you reset the error log and wait, does the error recur with the current plugin files.

    Anyway, “WC()->query->query_vars” is invalid at the point in time when this function is executed. You could try var_dump()ing this function’s return value to see what’s in there. Of course, debugging the code backwards from this point won’t be easy.

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘PHP Warning’ is closed to new replies.