After the last update on Woocommerce that occurred yesterday instantiating the constructor of class WC_Order is not working anymore as it got removed. What alternative can I use of the code below:

/wp-content/theme_name/framework/classes/themex.woo.php

class ThemexWoo {
    public static function getRelatedPost($ID, $type, $single=false) {
        $order = new WC_Order($ID);
        $products=$order->get_items();
        if(!empty($products)) {
            $ID=wp_list_pluck($products, 'product_id');
        }

        $relations=array_merge(array(0), ThemexCore::getPostRelations(0, $ID, $type));
        $posts=get_posts(array(
            'numberposts' => -1,
            'post_type' => array('course', 'plan'),
            'post__in' => $relations,
        ));

        if(!empty($posts)) {
            if($order->user_id) {
                foreach($posts as &$post) {
                    $post->post_author=$order->user_id;
                }
            }           

            if($single) {
                $posts=reset($posts);
            }
        }

        return $posts;
    }
}

/wp-content/theme_name/woocommerce/checkout/form-checkout.php

global $woocommerce;
$product=reset($woocommerce->cart->get_cart());
$related=ThemexWoo::getRelatedPost($product['product_id'], array('course_product', 'plan_product'), true);

Read more here: new WC_Order($order_id); Constructor disappeared


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: