Addon-item prices are purchased with plan-item prices in subscriptions. You can automate this process by configuring certain addons as “attached” to certain plans. This is done at the “item” level. In other words, the addon can be attached to plan items.
Once the attachment is defined, while creating or updating a subscription, the addon prices are selected automatically based on the plan-item price selected.
mandatoryAddonsToRemove() function is used when you have added an addon as a mandatory addon at the plan item level and you would like to remove this addon from being automatically applied to a subscription.
This Replace Addon would be the parameter that will have to be passed as true and do not pass anything in the addons; this would remove the existing addons in the subscription.
Here's the section you can refer to for more details.