A
A
Albert Ushakov2019-09-27 13:58:57
WordPress
Albert Ushakov, 2019-09-27 13:58:57

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);

He adds the order, but there is a problem. The default price on the product is 0. How can I set another one for it through the code?
When you replenish your account through the plugin, enter the amount of replenishment there and pay. How to do something like this here?
Please tell me (
5d8decd56367d689369866.png
There is another example, but an error pops up in it. That is, these lines do not work:
$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

1 answer(s)
A
Albert Ushakov, 2019-10-08
@fuck_ask

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 question

Ask a Question

731 491 924 answers to any question