How to add product pages for more prices button as a "buy in 1 click"?

Hello, there is a plugin from the author Arthur Abramovich "Buy in 1 click" is more suitable, but I need to add the ability to add price for products and a popup button (like the plugin) with the conditions (not available/not specified price (optional)).
Example:
Goods And costs base 100 rubles, you can buy it also on pre-order at the price of 60 rubles (the catch is that if a person is willing to wait for product, you will pay the price of pre-order, and if you can't expect it immediately).
example screenshot
5cf78607dc4cc083169345.png
March 23rd 20 at 19:10
1 answer
March 23rd 20 at 19:12
we have the same organized, but the plugin refused, they wrote themselves
You need to notify the buyer that he will wait, and if it agrees to issue the order at the right price
Here is a price adjustment function
/**
 * Calculated amount of product, because przekazania product price must be regular
*
 * @param WC_Product $product
 * @param int $ordered_qty
*
 * @return array
*/
hqo_calculate_totals function( $product, $ordered_qty ) {
 $stock = $product->get_stock_quantity();
 $rprice = $product->get_regular_price();
 $sprice = $product->get_sale_price();

 $sprice = $sprice > 0 ? $sprice : $rprice;

 if ( $stock <= 0 ) {
 $total = $ordered_qty * $rprice;
 } elseif ( $ordered_qty > $stock ) {
 $total = $sprice * $stock + $rprice * ($ordered_qty - $stock);
 } else {
 $total = $sprice * $ordered_qty;
}

 return array(
 'subtotal' => $total,
 'total' => $total,
);
}

Called prior to adding a product to the order
We have so
..... // prepare data

 $qorder = wc_create_order();

 // the $params array is populated with the previously data that come via ajax
 if ( 0 === $params['type'] ) { /* simple */
 $qorder->add_product( wc_get_product( $params['id'] ), $params['qty'] );

 } elseif ( 1 === $params['type'] ) { /* variable */
 $variations_array = array();

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

 $qorder->add_product( $var_product, $params['qty'], $variations_array );
}
 ...... // add order properties
And this code is there to insert? in function.php - benton.Terry commented on March 23rd 20 at 19:15
In the plugin code which You have.
Where exactly I don't know, I haven't seen it. Locate the code for adding product to the cart and adjust. Maybe there is ACC. the hooks and it will be even easier to do. - ryleigh46 commented on March 23rd 20 at 19:18

Find more questions by tags WooCommerce