menu

arrow_back How to change the quanity amount?

by
1 vote
Hi all.

How can I change the quanity number in the page Woocommerce? To on different product pages can be put different amounts of quanity?
5e56516ee0381955886908.png

2 Answers

by
0 votes
I decided this case this way:
Send the form via AJAX to the url '/wp-admin/admin-ajax.php'
In functions.php ordered the culling:
add_action( 'wp_ajax_nopriv_cart_update', 'cart_update' );
function cart_update() {
global $wpdb, $woocommerce;
session_start();
$res = [];
foreach ($_POST['cart'] AS $k => $v) {
$carti = WC()->instance()->cart;
$id = $v['product_id'];
$cart_id = $carti->generate_cart_id($id);
$cart_item_id = $carti->find_product_in_cart($cart_id);

if ($cart_item_id) {
$carti->set_quantity($cart_item_id, $v['qty']);
}
}
echo json_encode($res);
die;
}
by
0 votes