/**
  * Make sure the sign-up fee on a subscription line item takes into account sign-up fees paid for switching.
  *
  * @param WC_Subscription $subscription
  * @return array $cart_item Details of an item in WC_Cart for a switch
  * @since 2.0
  */
 public static function subscription_items_sign_up_fee($sign_up_fee, $line_item, $subscription)
 {
     // This item has never been switched, no need to add anything
     if (!isset($line_item['switched_subscription_item_id'])) {
         return $sign_up_fee;
     }
     // First add any sign-up fees for previously switched items
     $switched_line_items = $subscription->get_items('line_item_switched');
     foreach ($switched_line_items as $switched_line_item_id => $switched_line_item) {
         if ($line_item['switched_subscription_item_id'] == $switched_line_item_id) {
             $sign_up_fee += $subscription->get_items_sign_up_fee($switched_line_item);
             // Recursion: get the sign up fee for this item's old item and the sign up fee for that item's old item and the sign up fee for that item's old item and the sign up fee for that item's old item ...
             break;
             // Each item can only be switched once
         }
     }
     // Now add any sign-up fees paid in switch orders
     foreach (wcs_get_switch_orders_for_subscription($subscription->id) as $order) {
         foreach ($order->get_items() as $order_item_id => $order_item) {
             if (wcs_get_canonical_product_id($line_item) == wcs_get_canonical_product_id($order_item)) {
                 // We only want to add the amount of the line total which was for a prorated sign-up fee, not the amount for a prorated recurring amount
                 if (isset($order_item['switched_subscription_sign_up_fee_prorated'])) {
                     if ($order_item['switched_subscription_sign_up_fee_prorated'] > 0) {
                         $sign_up_proportion = $order_item['switched_subscription_sign_up_fee_prorated'] / ($order_item['switched_subscription_price_prorated'] + $order_item['switched_subscription_sign_up_fee_prorated']);
                     } else {
                         $sign_up_proportion = 0;
                     }
                 } else {
                     $sign_up_proportion = 1;
                 }
                 $sign_up_fee += round($order_item['line_total'] * $sign_up_proportion, 2);
             }
         }
     }
     return $sign_up_fee;
 }
 /**
  * Make sure the sign-up fee on a subscription line item takes into account sign-up fees paid for switching.
  *
  * @param WC_Subscription $subscription
  * @param string $tax_inclusive_or_exclusive Defaults to the value tax setting stored on the subscription.
  * @return array $cart_item Details of an item in WC_Cart for a switch
  * @since 2.0
  */
 public static function subscription_items_sign_up_fee($sign_up_fee, $line_item, $subscription, $tax_inclusive_or_exclusive = '')
 {
     // This item has never been switched, no need to add anything
     if (!isset($line_item['switched_subscription_item_id'])) {
         return $sign_up_fee;
     }
     // First add any sign-up fees for previously switched items
     $switched_line_items = $subscription->get_items('line_item_switched');
     // Default tax inclusive or exclusive to the value set on the subscription. This is for backwards compatibility
     if (empty($tax_inclusive_or_exclusive)) {
         $tax_inclusive_or_exclusive = 'yes' == $subscription->prices_include_tax ? 'inclusive_of_tax' : 'exclusive_of_tax';
     }
     foreach ($switched_line_items as $switched_line_item_id => $switched_line_item) {
         if ($line_item['switched_subscription_item_id'] == $switched_line_item_id) {
             $sign_up_fee += $subscription->get_items_sign_up_fee($switched_line_item, $tax_inclusive_or_exclusive);
             // Recursion: get the sign up fee for this item's old item and the sign up fee for that item's old item and the sign up fee for that item's old item and the sign up fee for that item's old item ...
             break;
             // Each item can only be switched once
         }
     }
     // Now add any sign-up fees paid in switch orders
     foreach (wcs_get_switch_orders_for_subscription($subscription->id) as $order) {
         foreach ($order->get_items() as $order_item_id => $order_item) {
             if (wcs_get_canonical_product_id($line_item) == wcs_get_canonical_product_id($order_item)) {
                 // We only want to add the amount of the line total which was for a prorated sign-up fee, not the amount for a prorated recurring amount
                 if (isset($order_item['switched_subscription_sign_up_fee_prorated'])) {
                     if ($order_item['switched_subscription_sign_up_fee_prorated'] > 0) {
                         $sign_up_proportion = $order_item['switched_subscription_sign_up_fee_prorated'] / ($order_item['switched_subscription_price_prorated'] + $order_item['switched_subscription_sign_up_fee_prorated']);
                     } else {
                         $sign_up_proportion = 0;
                     }
                 } else {
                     $sign_up_proportion = 1;
                 }
                 $order_total = $order_item['line_total'];
                 if ('inclusive_of_tax' == $tax_inclusive_or_exclusive && 'yes' == $order->prices_include_tax) {
                     $order_total += $order_item['line_tax'];
                 }
                 $sign_up_fee += round($order_total * $sign_up_proportion, 2);
             }
         }
     }
     return $sign_up_fee;
 }