Skip to content

Instantly share code, notes, and snippets.

@lukecav
Forked from eduwass/functions.php
Created January 11, 2018 03:14
Show Gist options
  • Save lukecav/60e3a0816c62f53b0efca29e671e678b to your computer and use it in GitHub Desktop.
Save lukecav/60e3a0816c62f53b0efca29e671e678b 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