samedi 21 novembre 2015

how to create order use wc_create_order with subscription product

I want to create a new order programmatically and I'm using the code below, this works well simple product type but my goal is to create a new order and convert this order to subscription product type with payment using the authorize.net

But I don't want customers to redirect to payment gateway, want to accept via API CALL.

<?php $address = array(
            'first_name' => 'Fresher',
            'last_name'  => 'StAcK OvErFloW',
            'company'    => 'stackoverflow',
            'email'      => 'test@test.com',
            'phone'      => '777-777-777-777',
            'address_1'  => '31 Main Street',
            'address_2'  => '', 
            'city'       => 'Chennai',
            'state'      => 'TN',
            'postcode'   => '12345',
            'country'    => 'IN'
        );

        $order = wc_create_order();
        $order->add_product( get_product( '4368' ), 2 ); //(get_product with id and next is for quantity)
        $order->set_address( $address, 'billing' );
        $order->set_address( $address, 'shipping' );
        //$order->add_coupon('Fresher','10','2'); // accepted param $couponcode, $couponamount,$coupon_tax
        $order->calculate_totals(); 
        $order->session->order_awaiting_payment = $order->id;

    // Process Payment
    $available_gateways = WC()->payment_gateways->get_available_payment_gateways();
    $result = $available_gateways[ 'ideal' ]->process_payment( $order->id );

    // Redirect to success/confirmation/payment page
    if ( $result['result'] == 'success' ) {

        $result = apply_filters( 'woocommerce_payment_successful_result', $result, $order->id );

        wp_redirect( $result['redirect'] );
        exit;
    }

        ?>



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire