Jump to content

Can anyone help with this please


Greystoke

Recommended Posts

Hi,

 

Can anyone help with this please.

 

    $products = $cart->get_products();
    print_r('$products');

}

 

print_r('$products');

 

outputs:

 

Array ( [0] => Array ( [id] => 28{7}14 [name] => Pro Install [model] => pro_install [image] => [price] => 25.0000 [quantity] => 1 [weight] => 0.00 [final_price] => 25 [tax_class_id] => 0 [attributes] => Array ( [7] => 14 ) ) [1] => Array ( [id] => 25 [name] => Keyboard [model] => KB [image] => intkeyboardps2.gif [price] => 69.9900 [quantity] => 1 [weight] => 8.00 [final_price] => 69.99 [tax_class_id] => 1 [attributes] => ) ) 

 

How do I get it to check the Array for 2 values, 'pro_install' and 'custom_install'.

If the values don't exits, I need it to redirect to index.php.

 

Link to comment
Share on other sites

Hi,

 

I tried this, but it didn't work.

 

    $products = $cart->get_products();
    print_r($products);
if(!isset($products['pro_install']) || !isset($products['custom_install']))
{
       echo 'test';

}

 

It still outputs 'test', even when 'pro_install' was in the Array.

Link to comment
Share on other sites

Please, next time post your print_r with the proper line breaks. Reading a multidimensional array in one line like that is a pain.

 

Here's the deal. $products has two members in your example, [0] and [1]. Each one of those is another array, which have other members. If 'pro_install' and 'custom_install' are supposed to be inside the 'model' key, try this:

foreach($products as $product) {
  if($product['model'] != 'pro_install' && $product['model'] != 'custom_install') {
    echo 'test';
  }
}

That will loop through each product in $products, echoing 'test' every time it doesn't match both.

Link to comment
Share on other sites

Sorry about not posting the print_r correctly.

 

What I want it to do is if 'pro_install' or 'custom_install' are not in the array, then redirect.

 

E.g.

If 'pro_install' is there don't redirect.

 

or

 

If 'custom_install' is there don't redirect.

 

or

 

If 'pro_install' and 'custom_install' are there don't redirect.

Link to comment
Share on other sites

So you're not sure it'll be the 'model' every time? In that case try this:

$found = false;
foreach($products as $product) {
  if(in_array('pro_install', $product) || in_array('custom_install', $product)) {
    $found = true;
    break;
  }
}
if(!$found) {
  //redirect
  exit;
} else {
  //do something else
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.