Title: Code error, please correct
Last modified: November 9, 2023

---

# Code error, please correct

 *  [Yan Knudtskov](https://wordpress.org/support/users/yannielsen/)
 * (@yannielsen)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/code-error-please-correct/)
 * In your latest version 6.0.0 you’re doing the following:
 * **File: /lib/bambora-online-classic-helper.php**
 *     ```wp-block-code
       public static function get_bambora_online_classic_subscription_id( $subscription ) {
       		$bambora_subscription_id = $subscription->get_meta(
       			self::BAMBORA_ONLINE_CLASSIC_SUBSCRIPTION_ID,
       			true
       		);
   
       		//For Legacy
       		if ( empty( $bambora_subscription_id ) ) {
       			$parent_order_id         = $subscription->get_parent_id();
       			$parent_order            = wc_get_order( $parent_order_id );
       			$bambora_subscription_id = $parent_order->get_meta(
       				self::BAMBORA_ONLINE_CLASSIC_SUBSCRIPTION_ID_LEGACY,
       				true
       			);
       			if ( ! empty( $bambora_subscription_id ) ) {
       				//Transform Legacy to new standards
       				$subscription->update_meta_data(
       					self::BAMBORA_ONLINE_CLASSIC_SUBSCRIPTION_ID,
       					$bambora_subscription_id
       				);
       				$subscription->save();
       				$parent_order->delete_meta_data(
       					self::BAMBORA_ONLINE_CLASSIC_SUBSCRIPTION_ID_LEGACY
       				);
       				$parent_order->save();
       			}
       		}
   
       		return $bambora_subscription_id;
       	}
       ```
   
 * On line 187 you’re assuming there’s a parent_order available, but if for some
   reason that parent order has been deleted, the code will throw a PHP Fatal.
 * **The correct code would be:**
 *     ```wp-block-code
       public static function get_bambora_online_classic_subscription_id($subscription)
           {
               $bambora_subscription_id = $subscription->get_meta(
                   self::BAMBORA_ONLINE_CLASSIC_SUBSCRIPTION_ID,
                   true
               );
   
               //For Legacy
               if (empty($bambora_subscription_id)) {
                   $parent_order_id         = $subscription->get_parent_id();
                   $parent_order            = wc_get_order($parent_order_id);
                   if($parent_order) {
                       $bambora_subscription_id = $parent_order->get_meta(
                           self::BAMBORA_ONLINE_CLASSIC_SUBSCRIPTION_ID_LEGACY,
                           true
                       );
                       if (! empty($bambora_subscription_id)) {
                           //Transform Legacy to new standards
                           $subscription->update_meta_data(
                               self::BAMBORA_ONLINE_CLASSIC_SUBSCRIPTION_ID,
                               $bambora_subscription_id
                           );
                           $subscription->save();
                           $parent_order->delete_meta_data(
                               self::BAMBORA_ONLINE_CLASSIC_SUBSCRIPTION_ID_LEGACY
                           );
                           $parent_order->save();
                       }
                   }
               }
   
               return $bambora_subscription_id;
           }
       ```
   

The topic ‘Code error, please correct’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/bambora-online-classic_6bcbbb.svg)
 * [Bambora Online ePay](https://wordpress.org/plugins/bambora-online-classic/)
 * [Support Threads](https://wordpress.org/support/plugin/bambora-online-classic/)
 * [Active Topics](https://wordpress.org/support/plugin/bambora-online-classic/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/bambora-online-classic/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/bambora-online-classic/reviews/)

 * 0 replies
 * 1 participant
 * Last reply from: [Yan Knudtskov](https://wordpress.org/support/users/yannielsen/)
 * Last activity: [2 years, 5 months ago](https://wordpress.org/support/topic/code-error-please-correct/)
 * Status: not resolved