in_array not working on get_downloadable_products()
-
Hey guys I’m pulling in a list of all downloads for a customer using
if ( $downloads = WC()->customer->get_downloadable_products() ) {
The problem is I’m not able to check for a [product_id] in that array using in_array. Using print_r on $downloads I can see there is a [product_id] and I need to check against that. Here’s by code:
if(in_array( $product->id , $downloads)) { //do something } ;
What am I doing wrong? If I run the array through a foreach loop like so:
<?php foreach ( $downloads as $download ) :
I can check no problem and it’s working using:
if ($download['product_id'] == $product->id) {
But I need to be able to check before I do a foreach loop. I need to be able to run
if ($download['product_id'] == $product->id) {
before I run the foreach.
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
- The topic ‘in_array not working on get_downloadable_products()’ is closed to new replies.