• There is a lot of PHP warning in the server error.log file like this:

    PHP Warning:  Attempt to read property “ID” on null in …/wp-content/plugins/woocommerce-unit-of-measure/public/class-wc-uom-public.php on line 86

    Since this plugin developer hasn’t fix this in months, I desided to give it a try. Here is how can you do it:

    1. Open the /public/class-wc-uom-public.php
    2. Find the line 83 where is like this: private function woo_uom_output_getter($uom_item_id = null) {
    3. After that line you need to change some lines.

    Old code:

    private function woo_uom_output_getter($uom_item_id = null) {
    if (is_null($uom_item_id)) {
    global $post;
    $uom_item_id = $post->ID;

    And you need to change into this:

            private function woo_uom_output_getter($uom_item_id = null) {
    if (is_null($uom_item_id)) {

                // global $post;

                // $uom_item_id = $post->ID;

                global $post, $product;

                // 1) If there is global $product

                if (isset($product) && is_a($product, 'WC_Product')) {

                    $uom_item_id = $product->get_id();

                    // 2) If there is $post

                } elseif (isset($post) && is_object($post) && isset($post->ID)) {

                    $uom_item_id = (int) $post->ID;

                    // 3) Queried object ID (single product page)

                } else {

                    $queried_id = get_queried_object_id();

                    if ($queried_id) {

                        $uom_item_id = (int) $queried_id;

                    }

                }

            }

            if (empty($uom_item_id)) {

                return '';

            }

    This is fix the code and error messages are gone. Plugin works as expected.

You must be logged in to reply to this topic.