• Resolved p13patch

    (@p13patch)


    I built a custom theme that is a child theme of storefront. One template creates a WooCommerce order programmatically by adding a product to the cart with the function:

    WC()->cart->add_to_cart($product_id);

    then I use these functions to create the order.

    $cart = WC()->cart;
     $checkout = WC()->checkout;
    
     $order_data = array();
     $order_data[ 'post_status' ] = 'wc-'.apply_filters( 'woocommerce_default_order_status', 'pending' );
     $order_id = $checkout->create_order($order_data);
    

    I can then get the order id and set billing address info and shipping address info. This has all worked so far, and I have successfully been able to programmatically create WooCommerce orders. I am running into an issue with paying for the order now.

    When I try to pay for the invoice, the payment fails. I have tested the payment gateway through the regular checkout process and it works fine, but trying to pay for an invoice, the payment always fails. I’ve tried assigning the order to a user, I’ve tried leaving it assigned to a guest, nothing works.

    I’m wondering if I created the order wrong, or if I am missing something.

    • This topic was modified 3 years, 2 months ago by p13patch.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi @p13patch

    This is a fairly complex development topic. I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.

    If you’re not receiving input on this thread, I can recommend reaching out to one of the customization experts listed here: https://woocommerce.com/customizations/.

    I can also recommend the WooCommerce Developer Resources Portal for resources on developing for WooCommerce.

    You can also visit the WooCommerce Facebook group or the #developers channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.

    Kindly be informed that this specific forum is more focused on the default WooCommerce core features.

    Seems we’ve not had additional inputs on this thread. Thus, I encourage you to make use of the above resources.

    That said, I’ll go ahead and mark the thread as closed but please feel free to create a new thread if you have further questions.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Dynamically created orders cannot be paid through WooCommerce payment gateways’ is closed to new replies.