I have many different product add-ons, global and product specific, and having to set code for every select dropdown would be difficult and unmanageable. The client wouldn’t be able to use it either.
This way if you need a 0 value you can just create the option for the add-on and label it “None”
For anyone wanting to set default values, 2023 showed us that we have this beautiful new tool called Chat GPT that can customize code for things like this! I wanted to have my checkbox for a bottle deposit selected by default so here is the code it generated and it works!
The price is only calculated and displayed when all addons have been selected. In this respect, it would make sense to be able to specify a default value
A dropdown of pre-configured values. I want customers to be able to select and apply suggested blocks of text to personalise their product e.g. special messages when buying gifts for others. Would be great if customers could edit the font of the text e.g. WYSIWYG editor/textarea
Did some research online and managed to put together a piece of code that worked for me! This will remove “Select an Option…” on the dropdown box (which appears if you set it to “Required”) and then set your first option to be the default option. I am not a developer though, so if this code is not working for you, please approach others. Just sharing what worked for me 🙂
jQuery(document).ready(function(){
jQuery(‘.wc-pao-addon-select option:contains(“Select an option…”)’).remove();
jQuery(‘.wc-pao-addon-select’).prop(‘selectedIndex’, 0);
});
We and our partners process your personal data (such as browsing data, IP Addresses, cookie information, and other unique identifiers) based on your consent and/or our legitimate interest to optimize our website, marketing activities, and your user experience.
Please add this, its super basic, we need defualt values for the add ons
Even the free version of Advanced Product Fields has this feature: https://wordpress.org/plugins/advanced-product-fields-for-woocommerce/
I too would like this. I want to include packaging by default, but allow customers to remove it for a saving
I realized that you can just remove the first “Select…” option from the .wc-pao-addon-select and it will set the next one as the default:
jQuery(document).ready(function(){
jQuery(‘.wc-pao-addon-select’).each(function(){
jQuery(this).find(‘option:first’).remove();
});
});
I have many different product add-ons, global and product specific, and having to set code for every select dropdown would be difficult and unmanageable. The client wouldn’t be able to use it either.
This way if you need a 0 value you can just create the option for the add-on and label it “None”
This plugin has default values for all field types built-in: https://www.studiowombat.com/plugin/advanced-product-fields-for-woocommerce/
You can add default values for all field types using the WooCommerce Product Add-Ons Ultimate plugin: https://pluginrepublic.com/wordpress-plugins/woocommerce-product-add-ons-ultimate/.
It’s strange that this has not been added yet after so long. For anyone looking, this feature is already included in the Advanced Product Fields plugin from Studio Wombat at https://www.studiowombat.com/plugin/advanced-product-fields-for-woocommerce/
If you want to change the function to something else, you just need to find which function that is.
Here are the available functions I could which need to be changed in the code for your use case:
wc-pao-addon-custom-price
wc-pao-addon-checkbox-group-required
wc-pao-addon-custom-text
For anyone wanting to set default values, 2023 showed us that we have this beautiful new tool called Chat GPT that can customize code for things like this! I wanted to have my checkbox for a bottle deposit selected by default so here is the code it generated and it works!
function add_custom_javascript() {
?>
jQuery(document).ready(function(){
jQuery(‘.wc-pao-addon-checkbox[value=”paper-bag-fee”]’).prop(“checked”, true);
});
<?php
}
add_action( 'wp_head', 'add_custom_javascript' );
Add this to your functions.php in your child theme or parent theme if you don't use a child theme.
Cant believe you cannot do this! I just tried, this sucks! please add this!
I would also like to have the option to set default values for checkboxes and radio buttons.
The price is only calculated and displayed when all addons have been selected. In this respect, it would make sense to be able to specify a default value
its stupid dont have this option. -.-!
Yes , please add the option to be able to create a draft product with a set of default parameters
A dropdown of pre-configured values. I want customers to be able to select and apply suggested blocks of text to personalise their product e.g. special messages when buying gifts for others. Would be great if customers could edit the font of the text e.g. WYSIWYG editor/textarea
if( $(‘[class*=”wc-pao-addon-wrap”]’).length )
$(‘[class*=”wc-pao-addon-wrap”]:first-of-type input’).prop(‘checked’, true);
f( $(‘[class*=”wc-pao-addon-wrap”]’).length )
$(‘[class*=”wc-pao-addon-wrap”]:first-of-type input’).prop(‘checked’, true);
It does not work!!!
Does anyone have a fix for that?
I must say I’m really surprised such basic feature is not there yet. I’ll look for another plugin because of this feature missing.
Incredible its not included… This is really important and basic in all similar plugins.
Did some research online and managed to put together a piece of code that worked for me! This will remove “Select an Option…” on the dropdown box (which appears if you set it to “Required”) and then set your first option to be the default option. I am not a developer though, so if this code is not working for you, please approach others. Just sharing what worked for me 🙂
jQuery(document).ready(function(){
jQuery(‘.wc-pao-addon-select option:contains(“Select an option…”)’).remove();
jQuery(‘.wc-pao-addon-select’).prop(‘selectedIndex’, 0);
});
Paste this in a plugin such as https://wordpress.org/plugins/custom-css-js/ with their “Add JS” option.
You can remove the line
jQuery(‘.wc-pao-addon-select option:contains(“Select an option…”)’).remove();
if you prefer to keep the “Select an option…”
Screenshot: https://share.getcloudapp.com/Blu5YwlW
please add this out of the box… kinda shocked it isn’t an option
Yes, please add the option to set default values for checkboxes and radio buttons, thanks!
I agree 100%. Not everyone knows and be assumed how to deal with coding. This is a must feature out-of-box.
Sorry, keusta, I don’t know Java Script
I really need this feature!