How to create and finish(bill) order imedeatly after “add to cart” clicked (Woocommerce)

I’m using Woo commerce plugin on my site but in the end of the process when user ordering a product(after “add to cart” , “checkout” and “billing” the last one don’t really exists) he gets to page where he have an access to download a file(that’s why the billing stage don’t really exist) that is the product.
The site based on memberships and I know it’s not the proper way for offering downloading products by membership, but it’s the way it is..

I need to prevent from user making all this long path through ‘add to cart’ , ‘checkout’ and ‘billing’ ( he need to pass 3-4 pages before he actually gets to the link) and get to the file downloading after he click ‘add to cart’ ,, by so i need some how create an order (with the product he selected) and bill it (all this on the background) and after he clicks ‘add to cart’ he already be redirected to downloading page(after the order been finalized )..

Read More

I’ve saw this link about redirecting to checkout page but it’s not enough ..
So how can I create some thing like this..

I know it’s kinda general question but I want to hear suggestions and if you can redirect me to some code it will be amazing…

Related posts

1 comment

  1. Solve it .. posting it here if somebody will deal with the same issue..
    implement it in functions.php

    add_filter ('woocommerce_add_to_cart_redirect', 'redirect_to_checkout');
    

    function redirect_to_checkout(){

                       global $woocommerce, $product, $post;
                            $args = array(
                                'status'        => 'processing',
                                'customer_id'   =>  get_current_user_id()
                            );
                            $order = wc_create_order( $args  );
                            $url = explode('?', 'http://'.$_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]);
                            $ID = url_to_postid($url[0]);
                            $order->add_product(get_product($ID));  
    
                    $address = null; // On my site I don't really need it.
                    $order->set_address( $address, 'billing' );
                    $order->set_address( $address, 'shipping' );
                    $order->calculate_totals();
                    $order->update_status( 'completed' );
    
                  $checkout_url = $order->get_view_order_url( );
    
     return $checkout_url;
    exit;
    }
    

Comments are closed.