I've got these functions which check product ids in cart but i need to check it against an array of product ids added to a form using the variable $products_ids.
Update 2 : This is the default var_dump for both arrays :
$products_ids as follows
array (size=2)
0 => int 111342
1 => int 111347
and $cart_ids
array (size=3)
'e877cbddd23b3bfa5b77782ba905b32e' => int 111347
'696d28043ad274014f653ca2d9a64812' => int 111342
'4363f14c8e54babb17770c2b4980ceed' => int 14535
And this is the new code i am trying :
function matched_ids() {
$cart_ids = array_merge(
wp_list_pluck(WC()->cart->get_cart_contents(), 'variation_id'),
wp_list_pluck(WC()->cart->get_cart_contents(), 'product_id')
);
$product_ids = get_option('restricted_product_ids');
$ids = array_map('intval', explode( ',', $product_ids ) );
return array_intersect( $ids, $cart_ids );
}
But it returns Array when i need it to check the $products_ids array against the $cart_ids array to find matched ids and output the matched_ids() function on the frontend to display matched string of product ids.
restricted_product_ids. Is it an array of ID's[1, 2, 3]? Is it a comma separated string of ID's'1,2,3'? Is it just a single ID1?