michel lompret
michel lompret

Reputation: 317

Add An If in A Foreach Loop

I'm trying to add part of a foreach loop on a condition like this:

foreach ( $woocommerce as $key => $woop ) {

  $type = $woop['woo'];

  if ( class_exists( 'WooCommerce' )  {

    $woo = array(
      'posts_per_page' => 3,
      'post_type'      => 'product',

      )

  }
}

But I got an error:

Parse error: syntax error, unexpected '{' for the  *if ( class_exists( 'WooCommerce' )  {*

Is there a way to add an if in a foreach loop ?

Upvotes: 0

Views: 257

Answers (1)

Joundill
Joundill

Reputation: 7543

You just forgot to close your bracket on the conditional

Replace your line with this if ( class_exists( 'WooCommerce' ) ) {

Upvotes: 3

Related Questions