Dynamically created orders cannot be paid through WooCommerce payment gateways
-
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.
- The topic ‘Dynamically created orders cannot be paid through WooCommerce payment gateways’ is closed to new replies.