L
L
Leonid2020-05-13 10:56:18
WordPress
Leonid, 2020-05-13 10:56:18

Use WooCommerce for payment in your plugin?

A lot of different payment modules have been written for WooCommerce - it's convenient: installed, configured and used ...

There is a hotel website with prepaid bookings and its own booking functionality.
You need to stick an online payment with the ability to change the payment module later.

So I don’t want to write integration with one payment system, then write another one for another payment system.
Is it possible to take and use WooCommerce for payment? But so that WooCommerce itself does not appear on the site - no checkout forms, carts, letters from WooCommerce - only payment from WooCommerce and that's it.

It turns out after the transition to payment from our own booking form on the site, you will need to:
* programmatically create a product in WooCommerce (booking)
* then programmatically add it to the cart
* then programmatically add the buyer's data from the booking form (name, phone, email)
* place an order and transfer the client to the payment form
* after payment, transfer the user to the page of the site I need and replace the payment / order letters from WooCommerce to my letter about the successful payment of the reservation

Has anyone seen such functionality somewhere?
I don’t want to reinvent the wheel and understand the thorns (features) WooCommerce is too deep)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
Leonid, 2020-05-13
@easycode

It seems I have already found an option, it remains only to apply and test:

if (isset($_POST['isOrder']) && $_POST['isOrder'] == 1) {
    $address = array(
        'first_name' => $_POST['notes']['domain'],
        'last_name'  => '',
        'company'    => $_POST['customer']['company'],
        'email'      => $_POST['customer']['email'],
        'phone'      => $_POST['customer']['phone'],
        'address_1'  => $_POST['customer']['address'],
        'address_2'  => '', 
        'city'       => $_POST['customer']['city'],
        'state'      => '',
        'postcode'   => $_POST['customer']['postalcode'],
        'country'    => 'NL'
    );
 
    $order = wc_create_order();
    foreach ($_POST['product_order'] as $productId => $productOrdered) :
        $order->add_product( get_product( $productId ), 1 );
    endforeach;
 
    $order->set_address( $address, 'billing' );
    $order->set_address( $address, 'shipping' );
 
    $order->calculate_totals();
 
    update_post_meta( $order->id, '_payment_method', 'ideal' );
    update_post_meta( $order->id, '_payment_method_title', 'iDeal' );
 
    // Store Order ID in session so it can be re-used after payment failure
    WC()->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;
    }
}

O
Orkhan Hasanli, 2020-05-13
@azerphoenix

If I were you, I wouldn’t tie up such huge Woocommerce functionality just because of the payment system. As for me, it's easier to read the documentation and write your own payment gateway in PHP.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question