Skip to content

Instantly share code, notes, and snippets.

@manospsyx
Last active February 29, 2020 20:36
Show Gist options
  • Save manospsyx/2e22ea276e6de813df4f to your computer and use it in GitHub Desktop.
Save manospsyx/2e22ea276e6de813df4f to your computer and use it in GitHub Desktop.
Use this snippet to override the initial quantity value of a bundled item (by default equal to the minimum quantity).
<?php
/**
* Plugin Name: WooCommerce Product Bundles - Default Bundled Item Quantity Override
* Plugin URI: https://woocommerce.com/products/composite-products/
* Description: Use this snippet to override the initial quantity value of a bundled item (by default equal to the minimum quantity).
* 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 ([email protected]).
* 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.
// Note: Here, a product bundle id = 1000 and a bundled item id = 500 are assumed. Replace these with your own values!
add_filter( 'woocommerce_bundled_product_quantity', 'wc_pb_default_product_quantity', 10, 4 );
function wc_pb_default_product_quantity( $default_qty, $min_qty, $max_qty, $bundled_item ) {
if ( intval( $bundled_item->get_id() ) === 500 ) {
$default_qty = 1;
}
return $default_qty;
}
@stefanboehm
Copy link

Hi,

I would like to have the text elements (for example "You have selected 2 items. Please select 6 items." etc) in German language, not in English like it is now. Is there a possibility to change this? I think i found the elements also in the Code of the Plugins PHP file, but i don't know if i can change it there.

Can you help me?

Thanks,
Stefan

@tourban
Copy link

tourban commented Jan 8, 2018

Hi everyone,

thanks for posting the code!
This is exactly the functionality I am looking for:
Changing the default quantity for specific items in specific bundles.

I have made the following changes in the code:
bundle_id (1000 -> 302)
item_id (500 -> 307)
$default_qty (1 -> 2)

I have copied the code into my functions.php. It doesn't work, though.

Anyone having an idea what the issue is?
Tobi

@JesterGroup
Copy link

I also have done this, making the three necessary changes - and it doesn't work for me. Theme used is Bento.

Any ideas anybody?!

Chris

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment