• Resolved lolitsjohnnyboy

    (@lolitsjohnnyboy)


    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 in WordPress. 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 the my account page, I can see the created order within the status pending.

    Now I’ve created a button on the view order page which also calls an AJAX 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

Viewing 1 replies (of 1 total)
  • Hi,

    This kind of question is out of scope for this channel as we don’t typically handle customization of the plugin, just the core features. If you require assistance with customization I recommend contacting one of the specialists found here: https://woocommerce.com/customizations/

    I’m also going to mark this topic as resolved since it is not something we can assist with here.

    Thanks!

Viewing 1 replies (of 1 total)
  • The topic ‘I need help with later order payment’ is closed to new replies.