Created
January 17, 2017 17:18
-
-
Save eduwass/0d7bbee5424171827ded00e4aa7ff776 to your computer and use it in GitHub Desktop.
WooCommerce Product Bundles - Check if cart contains a Product Bundle Container
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 | |
/** | |
* Checks if the cart contains a product bundle | |
* @return [bool] | |
*/ | |
function cart_contains_product_bundle(){ | |
global $woocommerce; | |
$contains_product_bundle = false; | |
if ( sizeof( WC()->cart->get_cart() ) > 0 ) { | |
// if cart has items | |
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { | |
// loop through each cart item | |
if(wc_pb_is_bundle_container_cart_item($cart_item)){ | |
// if its a bundle container product | |
$contains_product_bundle = true; | |
return $contains_product_bundle; | |
} | |
} | |
} | |
return $contains_product_bundle; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment