0

I am getting a E_WARNING error on my child theme template for woocommerce/content-product.php

Stack trace
E_WARNING: A non-numeric value encountered
in {closure} called at ? (?)
in array_walk called at /www/gmclassics_224/public/wp-content/themes/hill-child/woocommerce/content-product.php (230)
in require called at /www/gmclassics_224/public/wp-includes/template.php (690)
in load_template called at /www/gmclassics_224/public/wp-content/plugins/woocommerce/includes/wc-core-functions.php (181)
in wc_get_template_part called at /www/gmclassics_224/public/wp-content/plugins/woocommerce/includes/shortcodes/class-wc-shortcode-products.php (643)
in WC_Shortcode_Products::product_loop called at /www/gmclassics_224/public/wp-content/plugins/woocommerce/includes/shortcodes/class-wc-shortcode-products.php (100)
in WC_Shortcode_Products::get_content called at /www/gmclassics_224/public/wp-content/plugins/woocommerce/includes/class-wc-shortcodes.php (457)
in WC_Shortcodes::featured_products called at /www/gmclassics_224/public/wp-includes/shortcodes.php (319)
in do_shortcode_tag called at ? (?)
in preg_replace_callback called at /www/gmclassics_224/public/wp-includes/shortcodes.php (197)
in do_shortcode called at /www/gmclassics_224/public/wp-content/plugins/js_composer/include/helpers/helpers.php (236)
in wpb_js_remove_wpautop called at /www/gmclassics_224/public/wp-content/plugins/js_composer/include/templates/shortcodes/vc_column.php (94)
in include called at /www/gmclassics_224/public/wp-content/plugins/js_composer/include/classes/shortcodes/shortcodes.php (478)
in WPBakeryShortCode::loadTemplate called at /www/gmclassics_224/public/wp-content/plugins/js_composer/include/classes/shortcodes/shortcodes.php (458)
in WPBakeryShortCode::content called at /www/gmclassics_224/public/wp-content/plugins/js_composer/include/classes/shortcodes/shortcodes.php (570)
in WPBakeryShortCode::output called at /www/gmclassics_224/public/wp-content/plugins/js_composer/include/helpers/helpers.php (1311)
in vc_do_shortcode called at /www/gmclassics_224/public/wp-includes/shortcodes.php (319)
in do_shortcode_tag called at ? (?)
in preg_replace_callback called at /www/gmclassics_224/public/wp-includes/shortcodes.php (197)
in do_shortcode called at /www/gmclassics_224/public/wp-content/plugins/js_composer/include/helpers/helpers.php (236)

The code in question was written by a former developer and I cannot figure out how to prevent the above error and still maintain functionality. I'm not a PHP expert, so any help would be greatly appreciated.

<?php $yearsrange = array_column( wc_get_product_terms( $product->get_id(), 'fit_year' ), 'name');
    array_push($yearsrange, null);
    $rangeArray = array();

    array_walk($yearsrange, function($val) use (&$rangeArray){
        static $oldVal, $rangeStart;

            if (is_null($rangeStart))
                goto init;

            if ($oldVal+1 == $val) {
                $oldVal = $val;
                return;
            }

            if ($oldVal == $rangeStart) {
                array_push($rangeArray, $rangeStart);
                goto init;
            }

            array_push($rangeArray, $rangeStart . '-' . $oldVal);

            init: {
                $rangeStart = $val;
                $oldVal = $val;
            }


    });

    foreach($rangeArray as $val) {
        print $val;
    }

?>

The purpose of the code is to get the custom taxonomy fit_year (tags) for a product and make it more readable. e.g. 1972-1974 vs 1972, 1973, 1974.

Note: this is not woocommerce-specific, just a standard wordpress php question.

Any thoughts?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.