I'm using this function to check if certain products are in the cart on my woocommerce. This works on my localhost but is giving me a:
Can't use function return value in write context
on server.
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;
}}
I'm trying to find other methods to do this but i cant find a answer to my problem, I think is because of empty() but how can i do this on other way?
I see this is tagged php 5.3
In versions of php before 5.5 empty() will only accept a variable. You will need to assign it first like so:
$isEmpty = array_intersect($ids, $cart_ids);
if ( !empty($isEmpty) ) {
...
}
Upgrade your server's PHP.
Check the PHP version on your machine and the server. as mentioned in the documentation, in older version you could only pass the variable.
Prior to PHP 5.5, empty() only supports variables;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With