1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How do I add extra condition to "if" statement

Discussion in 'PHP' started by mylewicz, Mar 30, 2016.

  1. #1
    Hi, I'm new here, sorry if this is not the right place to post this but my developer is in a hospital and I have things falling apart, I have this:

    1.
    if($order->source == 'unknown')
    {
    $data->CustomerRef = $extra_field_1;
    }

    How can I add/merge that (1) with (2):

    2.
    if(($order->payment_method == 'collect_on_delivery') or strpos($order->delivery_method ,'pobraniowa'))
    {
    $data->CustomerRef = $order->delivery_package_nr;
    }else{
    $data->CustomerRef = $order->order_id;
    }
     
    mylewicz, Mar 30, 2016 IP
  2. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #2
    Depending on how $data->CustomerRef is constructed, you might be able to, but probably not.
    The problem here isn't merging the if-conditions, but to get more than one return-value. Ie, look at this code:
    
    if ($order->source == 'unknown' && (($order->payment_method == 'collect_on_delivery') || strpos($order->delivery_method ,'pobraniowa'))) {
       $data->CustomerRef = $extra_field_1;
       $data->CustomerRef = $order->delivery_package_nr;
    } else {
       $data->CustomerRef = $order->order_id;
    }
    
    PHP:
    That won't work (probably), because the return value if the first if-condition is correct will only return one of the $data-results (basically, the last one, the delivery package nr). So, depending on what you need, and what you want, you might need to rethink the whole thing.

    If you just want the whole thing to be ONE combined conditional, depending on different values, you could do something like this:
    
    if ($order->source == 'unknown') {
      $data->CustomerRef = $extra_field_1;
    } elseif (($order->payment_method == 'collect_on_delivery') || strpos($order->delivery_method,'pobraniowa')) {
      $data->CustomerRef = $order->delivery_package_nr;
    } else {
      $data->CustomerRef = $order->order_id;
    }
    
    PHP:
     
    PoPSiCLe, Mar 30, 2016 IP
  3. Rohit Oberoi

    Rohit Oberoi Greenhorn

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #4
    if(($order->payment_method == 'collect_on_delivery') or strpos($order->delivery_method ,'pobraniowa'))
    {
    $data->CustomerRef = $order->delivery_package_nr;
    }
    else if($order->source == 'unknown')
    {
    $data->CustomerRef = $extra_field_1;
    }
    else{
    $data->CustomerRef = $order->order_id;
    }
    Code (markup):
     
    Last edited by a moderator: Apr 20, 2016
    Rohit Oberoi, Apr 20, 2016 IP
  4. JeffH {wx}

    JeffH {wx} Greenhorn

    Messages:
    23
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    8
    #4
    It's a bit unclear as to your desired end logic but I'm assuming Rhohit has it right.
     
    JeffH {wx}, Apr 21, 2016 IP