wc_create_order can’t seem to call any functions on order created

I am trying to create an order with an ajax call.

The order seems to get created. $order->id is filled in with a valid number and I can redirect to that URL and edit. But my problem is I can’t seem to call any methods on the object. As soon as I call $order->save(); or $order->set_billing_first_name('Leo');. I get Call to undefined function save(). Then I get a 500 returned to ajax call.

$order = wc_create_order();

if (is_wp_error( $order )) {
    echo json_encode(array('error' => 'Order was not created. ERROR: '.$order->get_error_message()));
    die();
}

$order->billing_first_name = $firstName;
$order->save();


$url = admin_url( 'post.php?post='.$order->id.'&action=edit' );

echo json_encode(array('error' => '', 'url' => $url));
die();

Is there a way around this Or what is going on?
thanks
Leo

Read more here: wc_create_order can’t seem to call any functions on order created

Leave a Reply

Your email address will not be published. Required fields are marked *