Skip to content

Instantly share code, notes, and snippets.

@eduwass
Created January 17, 2017 17:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save eduwass/0d7bbee5424171827ded00e4aa7ff776 to your computer and use it in GitHub Desktop.
Save eduwass/0d7bbee5424171827ded00e4aa7ff776 to your computer and use it in GitHub Desktop.
WooCommerce Product Bundles - Check if cart contains a Product Bundle Container
<?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