Skip to content

Instantly share code, notes, and snippets.

@alexmustin
Last active March 23, 2018 21:09
Show Gist options
  • Save alexmustin/6519330a07a841b45a79fcb6daa7f253 to your computer and use it in GitHub Desktop.
Save alexmustin/6519330a07a841b45a79fcb6daa7f253 to your computer and use it in GitHub Desktop.
WooCommerce - is Product in Cart
<?php
function is_product_in_cart( $prodID ) {
$cartID = WC()->cart->generate_cart_id( $prodID );
$in_cart = WC()->cart->find_product_in_cart( $cartID );
if ( $in_cart ) {
return true;
}
return false;
}
/* USAGE:
-------------------- */
// Product ID
$myProd = 1234;
// See if Product is in Cart
if ( is_product_in_cart( $myProd ) {
// do stuff
return true;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment