user3579330
user3579330

Reputation: 11

Call to a member function get_items() on a non object in woocommerce

I am making a plugin that works in collaboration with woocommerce WordPress plugin. I am getting an error when trying to get items for an order:

"Fatal error: Call to a member function get_items() on a non-object in /home/telesqua/public_html/mehtab/wp-content/plugins/order-grabber/order-grabber.php on line 283"

and this is what is on line 283 and around it:

function post_order() 
{
if(isset($order_id))
{   
$order = new WC_Order($order_id);
}
$items = $order->get_items();
$number_of_items_in_this_order = $order->get_item_count();

Can anyone help me point out the problem? I can provide the source file if needed.

Upvotes: 1

Views: 4175

Answers (1)

user3697484
user3697484

Reputation:

this is because it an add_action has to be executed after using the above code

add_action('init', 'post_order');

Upvotes: 1

Related Questions