I am setting array of gift products on the cart. I have used woocommerce_cart_item_price to set the price of the product in the cart. However, it is adding price of last product in array to the subtotal.
add_filter('woocommerce_cart_item_price', 'filter_cart_item_price', 10, 3);
function filter_cart_item_price($price, $cart_item, $cart_item_key)
{
$valid_gift_products = WC()->session->get('valid_gift_products', []);
if (in_array($cart_item['product_id'], $valid_gift_products)) {
$price = wc_price(0);
}
return $price;
}
New contributor
Saugat Karki is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.