• In your latest version 6.0.0 you’re doing the following:

    File: /lib/bambora-online-classic-helper.php

    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:

    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.