Checkbox shortcode with multiple default values
-
Hi!
Is it possible to select multiple checkbox values in a shortcode tag?
My current setting:
Shortcode on different pages with different default values:
[contact-form-7 id="xxxxxxx" title="ContactForm1" wpcf7_chkbox_products1="Value3" wpcf7_chkbox_products2="Value2"]Form with checkboxes:
...
[checkbox wpcf7_chkbox_products1 default:shortcode_attr "Value1" "Value2" "Value3" "Value4"]
[checkbox wpcf7_chkbox_products2 default:shortcode_attr "Value1" "Value2"]
...functions.php:
add_filter( 'shortcode_atts_wpcf7', 'custom_shortcode_atts_wpcf7_filter', 10, 3 );
function custom_shortcode_atts_wpcf7_filter( $out, $pairs, $atts ) {
$my_attr = ['wpcf7_chkbox_products1', 'wpcf7_chkbox_products2'];
foreach ( $my_attr as $key => $value ) {
if(isset($atts[$value]))
{
$out[$value] = $atts[$value];
}
}
return $out;
}This works properly for one default value to be checked!
But how can I select multiple default values?
Example: wpcf7_chkbox_products1 should have “Value1” and “Value4” selected.Can anyone of you please help me with this? Thank you in advance!
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
The topic ‘Checkbox shortcode with multiple default values’ is closed to new replies.