• Resolved miroslavps

    (@miroslavps)


    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!

    • This topic was modified 5 years, 6 months ago by miroslavps.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Phil

    (@fullysupportedphil)

    Automattic Happiness Engineer

    Hey @miroslavps

    These forums are intended for support with the default functionality of WooCommerce, so there aren’t as many developers on here as other options.

    For this type of coding questions, you’re more likely to get input by asking in the WooCommerce Developer Slack or Advanced WooCommerce Facebook group. As those communities are both frequented by developers (including our own).

    Plugin Support Tseten a11n

    (@tibetanitech)

    We haven’t heard back from you in a while, so I’m going to mark this as resolved – if you have any further questions, you can start a new thread.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Manually create Order by saved Cart’ is closed to new replies.