S
S
Semyon Abezgauz2021-01-09 22:47:14
WordPress
Semyon Abezgauz, 2021-01-09 22:47:14

Separate payment for goods or another "buy in one click" - how?

Hello comrades!

Recently here in the wokomers section I saw a rather interesting question. At the time of checkout, the dude wanted to exclude certain items from the final price tag if there was another specific item in the cart at that time.

Well, this is + - understandable. But I went further.

It seems to me that the question was deleted, tk. the user realized that in this case all other goods "will be bought" for free. And this is clearly not what he needs. I'm even sure that the dude is sculpting another "one-click shopping" plugin.

Never thought about the work of these plug-ins for wokomers. And I'm stuck.

Question: how to separately buy goods in wookomers? I don't need plugins, I don't need "ready-made codes" either. I want to understand the logic and try to implement it.

looking for options. In the Russian segment, in the English ... Everything is spinning around, but does not answer the question.

How I decided: js + a little php. Algorithm:
0. Products from the category with the "test" slug have a "buy in one click" button (a standard button for adding an item to the cart). We press.
1. When you click on this button, the product from the category "test" falls into the basket + all products that are not included in the category with the slug "test" are removed from the basket + attention: these removed products fall into localstorage (can be improved to have synchronization between different browsers/devices, if this is done while in your account, and not as a guest).
2.A window opens, where the design form is pulled up. The window pretends to be indestructible and will not go anywhere until something is done to it or the design is finished.
3. If the "cross to close the window" is pressed, the window will disappear + the product from the "test" category will be removed from the basket + everything from the local storage will fall into the basket (from here I spied https://wordpress.stackexchange.com/questions/8696... )

Crutches are rolling. I especially "like" as many as three fatal functions on the closing cross. Brrr.
In general, this is not what can be called the norm option, IMHO. Everything is tied to the window, which, in turn, is some kind of jammer ... I

repeat the question, if I managed to forget:can I separate the clearance of goods from the basket? Issue separately depending on the type of goods mb? If someone has the norms of the algorithm for creating the "one-click shopping" plugin - it's also very interesting!

ps
Marking the question "Medium", because. I think that for experienced developers under wokomers this is + - an understandable task, and not "Difficult".

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pychev Anatoly, 2021-01-09
@abezgauz

Easier
For a one-click order, you don't need a shopping cart at all.
- Sending AJAX data about the product
- Create an order, fill in, checkout
As an example

$qorder = wc_create_order();

  if ( 0 === $params['type'] ) { /* simple */
    $product    = wc_get_product( $params['id'] );
    $item_id    = $qorder->add_product( $product, $params['qty'] );
  } elseif ( 1 === $params['type'] ) { /* variable */
    $variations_array = array();

    $var_product                   = new WC_Product_Variation( $params['var_id'] );
    $variations_array['variation'] = array(
      $params['attr_name'] => $params['attr_value'],
    );

    $item_id    = $qorder->add_product( $var_product, $params['qty'], $variations_array );
  }

  $qorder->set_address( $address, 'billing' );
  $qorder->set_address( $address, 'shipping' );

  $qorder->calculate_totals();
  wc_reduce_stock_levels( $qorder->get_id() );
  $qorder->update_status( 'processing' );
  echo 'Спасибо за заказ';

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question