Answer the question
In order to leave comments, you need to log in
How to add an invoice for payment from code through the Woocommerce Wallet plugin?
I installed a plugin for creating a wallet and the task was to upgrade it.
Everything works well, but is it possible to somehow add an invoice for payment from outside?
That is, for example, from the 1C customer base, a request goes to the site and adds an invoice for payment through the file, then the client goes to the page and simply clicks to pay.
I found an example of how to add an order, that is, an invoice for payment. It looks like this:
$address = array(
'first_name' => 'Альберт',
'last_name' => 'Ушаков',
'company' => 'Speed Society',
'email' => '[email protected]',
'phone' => '760-555-1212',
'address_1' => '123 Main st.',
'address_2' => '104',
'city' => 'San Diego',
'state' => 'Ca',
'postcode' => '92121',
'country' => 'RU'
);
$order_args = array(
'customer_id' => get_current_user_id(), // id пользователя который сделал заказ
);
$order = wc_create_order($order_args);
print_r(get_product('4534'));
$order->add_product( get_product('4534'), 1); // This is an existing SIMPLE product
$order->set_total( 100.00 ); //Думал так заработает, но нет, не обновляет
$order->set_address( $address, 'billing' );
$order->calculate_totals();
$order->update_status("Pending Payment", 'Imported order', TRUE);
$shipping = new stdClass();
$shipping->label = 'Code pay';
$shipping->id = 'code_pay';
$shipping->cost = 100.00;
$shipping->taxes = array();
$order->add_shipping($shipping);
Answer the question
In order to leave comments, you need to log in
Found a solution)
$order->add_product( get_product('4534'), 1);
$order->set_total(40, 'shipping');
$order->set_total(0, 'cart_discount');
$order->set_total(0, 'cart_discount_tax');
$order->set_total(0, 'tax');
$order->set_total(0, 'shipping_tax');
$order->set_total(40, 'total');
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question