Reputation: 317
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
Reputation: 7543
You just forgot to close your bracket on the conditional
Replace your line with this
if ( class_exists( 'WooCommerce' ) ) {
Upvotes: 3