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?