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:

<?php
/**
* Plugin Name: WooCommerce Product Bundles – Optional Items Checked by Default
* Plugin URI: https://woocommerce.com/products/product-bundles/
* Description: Use this plugin to have optional bundled items checked/selected by default.
* Version: 1.1
* Author: SomewhereWarm
* Author URI: https://somewherewarm.gr/
* Developer: Manos Psychogyiopoulos
*
* Requires at least: 4.1
* Tested up to: 5.3
*
* Copyright: © 2017-2020 SomewhereWarm SMPC (info@somewherewarm.gr).
* License: GNU General Public License v3.0
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
*/
add_filter( 'woocommerce_bundled_item_is_optional_checked', 'wc_pb_is_optional_item_checked', 10, 2 );
function wc_pb_is_optional_item_checked( $checked, $bundled_item ) {
if ( ! isset( $_GET[ 'update-bundle' ] ) ) {
$checked = true;
}
return $checked;
}

 

Remove the “optional” suffix from optional bundled item titles ↑ Back to top

By default, the extension adds an “- optional” suffix next to the title of bundled items that have been marked as optional. To remove this suffix, use the following snippet/plugin:

<?php
/**
* Plugin Name: WooCommerce Product Bundles – Remove Optional Suffix
* Plugin URI: https://woocommerce.com/products/product-bundles/
* Description: Use this snippet to remove the "- optional" suffix displayed next to the title of optional bundled items.
* Version: 1.0
* Author: SomewhereWarm
* Author URI: https://somewherewarm.gr/
* Developer: Manos Psychogyiopoulos
*
* Requires at least: 4.1
* Tested up to: 5.3
*
* Copyright: © 2017-2020 SomewhereWarm SMPC (info@somewherewarm.gr).
* License: GNU General Public License v3.0
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
*/
add_filter( 'woocommerce_bundles_optional_bundled_item_suffix', 'wc_pb_remove_optional_suffix', 10, 3 );
function wc_pb_remove_optional_suffix( $suffix, $bundled_item, $bundle ) {
return '';
}

 

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:

<?php
/**
* Plugin Name: WooCommerce Product Bundles – Discounts over Regular Prices
* Plugin URI: https://woocommerce.com/products/product-bundles/
* Description: Use this snippet to apply bundled item discounts on regular prices.
* Version: 1.0
* Author: SomewhereWarm
* Author URI: https://somewherewarm.gr/
* Developer: Manos Psychogyiopoulos
*
* Requires at least: 3.8
* Tested up to: 5.3
*
* Copyright: © 2017-2020 SomewhereWarm SMPC (info@somewherewarm.gr).
* License: GNU General Public License v3.0
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
*/
// To use this snippet, download this file into your plugins directory and activate it, or copy the code under this line into the functions.php file of your (child) theme.
add_filter( 'woocommerce_bundled_item_discount_from_regular', 'wc_pb_bundled_item_discount_from_regular', 10, 2 );
function wc_pb_bundled_item_discount_from_regular( $from_regular, $bundled_item ) {
return true;
}

 

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:

<?php
/**
* Plugin Name: WooCommerce Product Bundles – Prevent Range-Format Prices
* Plugin URI: https://woocommerce.com/products/product-bundles/
* Description: Use this snippet to prevent Product Bundles from displaying bundle prices in range format.
* Version: 1.0
* Author: SomewhereWarm
* Author URI: https://somewherewarm.gr/
* Developer: Manos Psychogyiopoulos
*
* Requires at least: 4.1
* Tested up to: 5.3
*
* Copyright: © 2017-2020 SomewhereWarm SMPC (info@somewherewarm.gr).
* License: GNU General Public License v3.0
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
*/
// To use this snippet, download this file into your plugins directory and activate it, or copy the code under this line into the functions.php file of your (child) theme.
add_filter( 'woocommerce_bundle_force_old_style_price_html', '__return_true' );

 

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:

<?php
/**
* Plugin Name: WooCommerce Product Bundles – Bundled Items Grid Layout column count
* Plugin URI: http://woocommerce.com/products/product-bundles/
* Description: Use this snippet to change the bundled items column count when using the 'Grid' Layout option.
* Version: 1.0
* Author: SomewhereWarm
* Author URI: http://somewherewarm.gr/
* Developer: Jason Kytros
*
*
* Copyright: © 2018 Jason Kytros (jask@somewherewarm.gr).
* License: GNU General Public License v3.0
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
*/
add_filter( 'woocommerce_bundled_items_grid_layout_columns', 'wc_pb_grid_layout_change_number_of_columns', 10, 2 );
function wc_pb_grid_layout_change_number_of_columns( $columns, $bundle ) {
return 4;
}

 

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:

<?php
/**
* Plugin Name: WooCommerce Product Bundles – Prevent Subtotals Aggregation
* Plugin URI: https://woocommerce.com/products/product-bundles/
* Description: Prevents Product Bundles from displaying aggregated item subtotals in cart/order templates. Requires v5.5+.
* Version: 1.0
* Author: SomewhereWarm
* Author URI: https://somewherewarm.gr/
* Developer: Manos Psychogyiopoulos
*
* Requires at least: 4.1
* Tested up to: 5.3
*
* Copyright: © 2017-2020 SomewhereWarm SMPC (info@somewherewarm.gr).
* License: GNU General Public License v3.0
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
*/
add_filter( 'woocommerce_bundles_group_mode_options_data', 'sw_pb_group_mode_options_data' );
function sw_pb_group_mode_options_data( $data ) {
$data[ 'parent' ][ 'features' ] = array( 'parent_item', 'child_item_indent' );
return $data;
}

 

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!

WooCommerce - the most customizable eCommerce platform for building your online business.

Back to the top