I use this function to check if certain products are in the cart in my woocommerce. This works on my localhost, but gives me:
Cannot use function return value in record 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 try to find other methods for this, but I can not find the answer to my problem, I think this is due to empty (), but how can I do it differently?
source share