Created
September 3, 2025 06:15
-
-
Save pramodjodhani/dba63a86705443a3bb3a21ba548dda41 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Check cart for given product id product. | |
* | |
* @param array $categories Categories. | |
* | |
* @return bool | |
*/ | |
function iconic_check_for_cart_item_in_cart( $product_ids = array() ) { | |
if ( empty( $product_ids ) || empty( WC()->cart ) ) { | |
return false; | |
} | |
// Set our flag to be false until we find a product with matching ID. | |
$has_item = false; | |
// Loop through cart items to check for matching product IDs. | |
foreach ( WC()->cart->get_cart() as $cart_item ) { | |
$product_id = $cart_item['product_id']; | |
if ( in_array( $product_id, $product_ids ) ) { | |
$has_item = true; | |
break; | |
} | |
} | |
return $has_item; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment