Last active
March 23, 2018 21:09
-
-
Save alexmustin/6519330a07a841b45a79fcb6daa7f253 to your computer and use it in GitHub Desktop.
WooCommerce - is Product in Cart
This file contains 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 | |
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