I am trying to programmatically update the quantity of a certain product in the basket if certain criteria are met.
I can easily update the price of the goods in the basket as follows:
add_action( 'woocommerce_before_calculate_totals', 'wwpa_simple_add_cart_price' );
function wwpa_simple_add_cart_price( $cart_object ) {
foreach ( $cart_object->cart_contents as $key => $value ) {
$value['data']->price = '1';
}}
In the function above, I tried to add:
$value['data']->quantity= '10';
This does not work, but not quite sure how or if I can change the quantity?
I also tried these combinations, which I found while delving into WooCommerce:
$value['data']->quantity= '10';
$value['data']->qty= '10';
$value['quantity'] = '10';
Again, none of this worked.
danyo source
share