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
↑ Revenir en hautMake optional bundled items checked/selected by default
↑ Revenir en hautBy default, optional bundled item checkboxes are unticked by default. This can be changed with the following snippet:
Show an “optional” suffix in optional bundled item titles
↑ Revenir en hautTo add an “- optional” suffix next to the title of bundled items that have been marked as optional, use the following snippet/plugin:
Calculate discounted bundled item prices over regular prices
↑ Revenir en hautBy 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:
Prevent product bundles price strings from showing up in range-format
↑ Revenir en hautEnsure that you are using the latest version of Product Bundles, then use the following snippet/plugin:
Change the number of bundled product columns displayed when the Grid Layout option is active
↑ Revenir en hautThe following snippet demonstrates how to adjust the number of bundled item columns to 4:
Change the appearance of item subtotals in the cart/orders
↑ Revenir en hautWhen 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:
Hide the remaining stock of the parent item
↑ Revenir en hautBy 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:
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:
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:
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:
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:
Hide bundles from Upsells if all bundled products are out of stock
↑ Revenir en hautadd_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
↑ Revenir en hautadd_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
↑ Revenir en hautHave 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!