Mid*_*oud 5 php wordpress php-5.3 woocommerce
我正在使用此功能检查我的woocommerce上的某些产品是否在购物车中.这适用于我的localhost但是给了我一个:
在写上下文中不能使用函数返回值
在服务器上.
function product_is_in_the_cart() {
$ids = array( '139, 358, 359, 360' );
$cart_ids = array();
// Find each product in the cart and add it to the $cart_ids array
foreach( WC()->cart->get_cart() as $cart_item_key => $values ) {
$cart_product = $values['data'];
$cart_ids[] = $cart_product->id;
}
// Si uno de los productos introducidos en el array esta, devuelve false
if ( ! empty( array_intersect( $ids, $cart_ids ) ) ) {
return true;
} else {
return false;
}}
Run Code Online (Sandbox Code Playgroud)
我试图找到其他方法来做到这一点,但我找不到我的问题的答案,我认为是因为空()但我怎么能在其他方式做到这一点?
我看到它被标记为 php 5.3
在 5.5 之前的 php 版本中,empty()只接受变量。您需要先像这样分配它:
$isEmpty = array_intersect($ids, $cart_ids);
if ( !empty($isEmpty) ) {
...
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
514 次 |
| 最近记录: |