Reputation: 347
inside a custom plugin placed this code to get an order:
global $woocommerce;
$order = new WC_Order(5273);
(and i have the order with 5273 in the database), but the result is:
Fatal error: Cannot use object of type WP_Error as array in D:\www\htdocs..\wp-content\plugins\woocommerce\includes\class-wc-order.php on line 83
What is the problem?
Upvotes: 0
Views: 2600
Reputation: 347
I finally figured out the problem. I called the code above inside the initialization hook, like this:
add_action('init', 'my_init', 1);
function my_init(){
$order = new WC_Order(5273);
}
the last argument in add_action is the priority and that was the point. 1 is the highest priority and my function is being called before the taxonomy registrations. I changed 1 to 100 and the code is working perfectly.
Upvotes: 1