I am testing some code for a local wordpress site and am editing the theme's functions.php file. As i was writing the below code, it just return a blank site. Anyone can enlighten me? i tried turning on error reporting on WAMP, but nothing appears.
global $woocommerce;
$box_found = false;
$voucher_found = false;
$other_products_found = false;
//start of the loop that fetches the cart items
foreach($woocommerce->cart->get_cart() as $cart_item_key => $values ) {
$_product = $values['data'];
$terms = get_the_terms( $_product->id, 'product_cat' );
// second level loop search, in case some items have several categories
foreach ($terms as $term) {
$_categoryid = $term->term_id;
}
//check if BOX product category is in card
if ( $_categoryid === 103 ) {
//category is in cart!
$box_found = true;
}
//check if VOUCHER product category is in card
if ( $_categoryid === 106 ) {
//category is in cart!
$voucher_found = true;
}
//check if VOUCHER product category is in card
if (( $_categoryid !== 103 )||($_categoryid !== 106 )) {
//category is in cart!
$other_products_found = true;
}
}
However, when i enclose the entire code in a function, then the webpage returns to normal.