Replies: 0
Hi,
I am stuck in something I would like to implement on my Woocommerce.
I have variable products with a quantity attribute. Price depends on quantity.
Thing is, my quantity is an attribute so in my cart it is not the right quantity… I wanted to change this quantity with a function in order to replace it with my attribute, and then multiplicate quantity * price to have the right total on the right of the cart.
Do you know if this could be possible ? I hanven’t been able to find any solution for this.
I tried something like this :
add_action('woocommerce_loop_add_to_cart_link', 'change_quantity_cart');
function change_quantity_cart( $cart_object ){
foreach( $cart_object->get_cart() as $cart_item_key => $cart_item) {
$item_id = $cart_item['product_id']; // Item Id or product ID
$marquage = $cart_item['variation']['attribute_pa_marquage'];
$cart_object->set_quantity($cart_item_key, $marquage, true);
}
}
I can provide you any other information you could need.
Thank you !