新的WC_Order($ order_id);构造函数消失了

时间:2017-04-05 14:30:28

标签: php wordpress oop woocommerce

昨天发生的WooCommerce上次更新后,实例化类WC_Order的构造函数不再有效,因为它已被删除。我可以使用以下代码的替代方案:

/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);

0 个答案:

没有答案