我正在测试本地wordpress网站的一些代码,并正在编辑主题的functions.php文件。当我写下面的代码时,它只返回一个空白站点。谁能开导我?我尝试打开WAMP的错误报告,但没有出现。
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;
}
}
但是,当我将整个代码包含在函数中时,网页将恢复正常。