Can I change WooCommerce quantity in some specific product?
I have tried:
global $woocommerce;
$items = $woocommerce->cart->get_cart();
foreach($items as $item => $values) {
$_product = $values['data']->post;
echo "<b>".$_product->post_title.'</b> <br> Quantity: '.$values['quantity'].'<br>';
$price = get_post_meta($values['product_id'] , '_price', true);
echo " Price: ".$price."<br>";
}
How to get specific product Id in cart?
To change quantities, see after that code. Here your revisited code:
Updated: Now to change the quantity on specific products, you will need to use this custom function hooked in
woocommerce_before_calculate_totals
action hook:Code goes in function.php file of the active child theme (or active theme).
Tested and works