Manually create Order by saved Cart
-
Hi to all,
I want to ask about a small functionality in a plugin I work on.
My idea is to save the Cart as serialized object. Then unserialize it and create an Order by this object.At the moment I try to do it as following:
$cart = unserialize(file_get_contents($cart_file));
$order = wc_create_order(); // optionally I pass here status and customer id
WC()->checkout->create_order_line_items($order, $cart);But at the end I get
Notice: get_cart was called incorrectly. Get cart should not be called before the wp_loaded action. Backtrace: require(‘wp-blog-header.php’), require_once(‘wp-load.php’), require_once(‘wp-config.php’), require_once(‘wp-settings.php’), do_action(‘init’), WP_Hook->do_action, WP_Hook->apply_filters, sc_enqueue, WC_SC->process_dmns, WC_SC->sc_get_order_by_tans_id, WC_Checkout->create_order_line_items, WC_Cart->get_cart, wc_doing_it_wrong Please see Debugging in WordPress for more information. (This message was added in version 2.3.) in …/woocommerce/wp-includes/functions.php on line 5225
Notice: get_cart was called incorrectly. Get cart should not be called before the wp_loaded action. Backtrace: require(‘wp-blog-header.php’), require_once(‘wp-load.php’), require_once(‘wp-config.php’), require_once(‘wp-settings.php’), do_action(‘init’), WP_Hook->do_action, WP_Hook->apply_filters, sc_enqueue, WC_SC->process_dmns, WC_SC->sc_get_order_by_tans_id, WC_Checkout->create_order_line_items, WC_Cart->get_cart, WC_Cart_Session->get_cart_from_session, do_action(‘woocommerce_cart_loaded_from_session’), WP_Hook->do_action, WP_Hook->apply_filters, WC_Cart_Session->set_session, WC_Cart_Session->get_cart_for_session, WC_Cart->get_cart, wc_doing_it_wrong Please see Debugging in WordPress for more information. (This message was added in version 2.3.) in …/woocommerce/wp-includes/functions.php on line 5225
And I have new order with amout 0.00.
Any help what I am doing wrong?Thanks and best reagards!
The topic ‘Manually create Order by saved Cart’ is closed to new replies.