Automatically change insurance quantity based on cart total [closed]

Try this: add_action(‘woocommerce_cart_totals_after_shipping’, ‘wc_shipping_insurance_note_after_cart’); function wc_shipping_insurance_note_after_cart() { global $woocommerce; // Get the number of products in the cart $cart_item_count = WC()->cart->get_cart_contents_count(); $product_id = 7597; // ID of the insurance product // Check if the insurance product is already in the cart $found = false; foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $values ) { $_product = … Read more