Answer the question
In order to leave comments, you need to log in
How to checkout without a shopping cart?
Hello, here is the issue. I need to make it possible to place an order from a custom form, where there is only a phone number and a name. And after filling out this form and selecting a product in the select, immediately send it to the gateway. In general, the chip works, but as it turned out, because I was logged in. In the case of a normal user, the redirect goes to an empty cart via the checkout link. Tell me where to dig? I use the following code:
$variant_id = $_POST['count'];
$address = array(
'first_name' => $_POST['name'],
'phone' => $_POST['phone'],
);
$order = wc_create_order();
$order->add_product(wc_get_product( $variant_id ), 1 );
$order->set_address( $address, 'billing' );
$order->set_address( $address, 'shipping' );
$order->calculate_totals();
update_post_meta( $order->get_id(), '_payment_method', 'rbspayment' );
update_post_meta( $order->get_id(), '_payment_method_title', 'Альфабанк' );
WC()->session->order_awaiting_payment = $order->get_id();
$available_gateways = WC()->payment_gateways->get_available_payment_gateways();
$result = $available_gateways[ 'rbspayment' ]->process_payment( $order->get_id() );
if ( $result['result'] == 'success' ) {
echo $result['redirect'];
exit;
}
exit;
Answer the question
In order to leave comments, you need to log in
Issue resolved.
Added:
global $woocommerce;
$woocommerce->cart->add_to_cart(id товара);
WC()->session->order_awaiting_payment = $order->get_id();
$available_gateways = WC()->payment_gateways->get_available_payment_gateways();
$result = $available_gateways[ 'rbspayment' ]->process_payment( $order->get_id() );
WC()->session->
there's a problem!
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question