I need help with later order payment
-
It’s hard to find someone who has a good knowledge about WooCommerce. I’ve tried very hard to get this done so please don’t judge me that I’m asking here now.
So my plan is it to get a programmatically created order via a button back in to cart and redirect directly to the checkout:
First, I’ve build a form which get’s submitted via
AJAX
inWordPress
. Within the AJAX function, I’m doing some checks and validations of the submitted form data.Finally, I’m creating an order and a product which get’s added to the order during this process:
$id = wp_insert_post( array( 'post_title' => sanitize_text_field( $title ), 'post_type' => 'product', 'post_status' => 'pending', 'post_excerpt' => sanitize_textarea_field( $short_description ), 'post_content' => sanitize_textarea_field( $description ) ) ); if ( ! empty( $id ) ) { $order = wc_create_order(); try { $order->add_product( wc_get_product( $id ) ); $order->set_customer_id( get_current_user_id() ); $order->calculate_totals(); } catch ( WC_Data_Exception $e ) { wp_send_json_error( null, 500 ); wp_die(); } }
When I’m visiting now the
orders page
on themy account page
, I can see the created order within the statuspending
.Now I’ve created a button on the
view order page
which also calls anAJAX
function. This function handles some custom things.What I need now, is a part of code within my
AJAX
function, that clears the current cart of the user, adds the nearly created order via the form to the cart and finally do a direct redirect to the checkout page so that the customer can enter his address and select the payment method to finally pay the order.I know that there is a method called
wp_safe_redirect();
but I’m not sure how to deal with this at all. Any help would be awesome.Visualization of the process
https://i.stack.imgur.com/XJyq0.png
- The topic ‘I need help with later order payment’ is closed to new replies.