1. Documentation /
  2. Product Bundles /
  3. Snippets

Snippets

Use these snippets to customize the appearance and functionality of WooCommerce Product Bundles.

To use a snippet, download the linked file and activate it as you would with any other plugin. Alternatively, copy the contained code into your child theme’s functions.php file.

Note: We are unable to provide support for customizations under our Support Policy. If you need to customize a snippet, or extend its functionality, seek assistance from a qualified WordPress/WooCommerce Developer. We highly recommend Codeable, or a Certified WooExpert.

Snippets

↑ Back to top

Make optional bundled items checked/selected by default

↑ Back to top

By default, optional bundled item checkboxes are unticked by default. This can be changed with the following snippet:

View on Github

Show an “optional” suffix in optional bundled item titles

↑ Back to top

To add an “- optional” suffix next to the title of bundled items that have been marked as optional, use the following snippet/plugin:

View on Github

Calculate discounted bundled item prices over regular prices

↑ Back to top

By default, a bundled item discount can co-exist with a sale price, reducing the final price of a bundled product even further.

Alternatively, you may prefer to ignore sale prices and apply bundled product discounts over the regular prices of bundled products. This is possible with the following snippet:

View on Github

Prevent product bundles price strings from showing up in range-format

↑ Back to top

Ensure that you are using the latest version of Product Bundles, then use the following snippet/plugin:

View on Github

Change the number of bundled product columns displayed when the Grid Layout option is active

↑ Back to top

The following snippet demonstrates how to adjust the number of bundled item columns to 4:

View on Github

Change the appearance of item subtotals in the cart/orders

↑ Back to top

When the Grouped selection is active under Item Grouping, the subtotals of parent/child line items in cart/order templates are added together and the actual subtotal of the parent item is replaced by the aggregated subtotal. Additionally, the subtotals of individually-priced items are indented and displayed with a Subtotal: prefix.

To prevent this, use the following snippet/plugin:

View on Github

Hide the remaining stock of the parent item

↑ Back to top

By default, the stock of a Product Bundle is calculated based on the remaining stock of the bundled items.

To calculate the stock of the bundle based on the stock of parent item instead, which is defined under Product Data > Inventory, use the following snippet:

View on Github

Hide the short description that shows up for each Bundle-Sell

To hide the short description that shows up for each Bundle-Sell, use the following snippet:

View on Github

Set the Bundle Sells layout to Grid

To change the default Bundle-Sells layout and make them show up in a Grid layout, use the following snippet:

View on Github

Set the Bundle Sells layout to Tabular

To change the default Bundle-Sells layout and make them show up in a Tabular layout, use the following snippet:

View on Github

Display the bundled products’ full description

By default, bundled items display the short description of the corresponding Simple/Variable products.

To display the full description, use the following snippet:

View on Github

Hide bundles from Upsells if all bundled products are out of stock

↑ Back to top
add_filter( 'woocommerce_product_is_visible', 'wc_hide_insufficient_stock_bundles_from_upsells', 10, 2 );

function wc_hide_insufficient_stock_bundles_from_upsells( $visible, $product_id ) {

	if ( ! $visible ) {
		return $visible;
	}

	$product_type = WC_Data_Store::load( 'product' )->get_product_type( $product_id );

	if ( 'bundle' === $product_type ) {

		$bundle = wc_get_product( $product_id );

		if ( 'yes' === get_option( 'woocommerce_hide_out_of_stock_items' ) && ! $bundle->is_in_stock() ) {
			$visible = false;
		}
	}
	return $visible;
}

Hide out of stock items in a bundle

↑ Back to top
add_filter( 'woocommerce_bundled_items', 'sw_remove_out_of_stock_items', 10, 2 );

function sw_remove_out_of_stock_items( $bundled_items, $bundle ) {
    foreach ( $bundled_items as $key => $bundled_item ) {
        if ( $bundled_item->is_optional() || $bundled_item->get_quantity( 'min' ) == 0 ) {
            if ( 'outofstock' === $bundled_item->product->get_stock_status() ) {
                unset( $bundled_items[ $key ] );
            }
        }
    }
    return $bundled_items;
}

Questions & Support

↑ Back to top

Have a question before you buy? Please fill out this pre-sales form.
Already purchased and need assistance? Get in touch with us via the Help Desk!