Home / Forums / Lafka – Fast Food Ordering WooCommerce Theme / ResolvedMinimum Number of Selectable Options
ResolvedMinimum Number of Selectable Options
- This topic has 2 replies, 2 voices, and was last updated 3 years, 3 months ago by
mediamix.
Viewing 3 posts - 1 through 3 (of 3 total)
- AuthorPosts
- June 19, 2020 at 7:21 pm #23729
mediamix
ParticipantHi
Is possible to add “Minimum Number of Selectable Options” in Lafka Global Add-on?June 30, 2020 at 7:19 pm #23899Althemist
KeymasterHello mediamix,
No, I am afraid it’s currently not possible. You can only set a max number of options, but I will discuss with the team if we can add a minimum too. Can’t promise, though.
June 30, 2020 at 7:37 pm #23907mediamix
ParticipantHi guys,
i have add this snippet into my child themeadd_action( 'woocommerce_validate_posted_addon_data', 'min_limit_validate'); function min_limit_validate ( $addon ) { if ( isset( $_POST ) ) { $post_data = $_POST; } else { return true; } if (!isset($addon['minlimit'])) { return true; } $value = isset( $post_data[ 'addon-' . $addon['field-name'] ] ) ? $post_data[ 'addon-' . $addon['field-name'] ] : ''; if (count($value) < $addon['minlimit']) { error_log (print_r($addon,true)); wc_add_notice( 'Select minimum ' . $addon['minlimit'] . ' elements from ' . $addon['name'], 'error' ); return false; } else { return true; } } add_action( 'lafka_product_addons_panel_before_options', 'add_minimum_selectable_options_field', 10, 3) ; function add_minimum_selectable_options_field ($post, $addon, $loop ) { ?> <tr> <td class="addon_minlimit"> <label for="addon_minlimit_<?php echo $loop; ?>"><?php esc_html_e( 'Minimum Number of Selectable Options', 'lafka-plugin' ); ?></label> </td> <td class="addon_minlimit"> <label for="addon_minlimit_<?php echo $loop; ?>"> <input type="number" id="addon_minlimit_<?php echo $loop; ?>" name="product_addon_minlimit[<?php echo $loop; ?>]" value="<?php echo isset($addon['minlimit']) ? esc_attr( $addon['minlimit'] ) : '' ?>" /> </label> </td> </tr> <?php } add_filter( 'lafka_product_addons_save_data', 'filter_lafka_product_addons_save_data', 10, 2); function filter_lafka_product_addons_save_data($data, $i ) { $addon_minlimit = $_POST['product_addon_minlimit']; $data['minlimit'] = sanitize_text_field( stripslashes( $addon_minlimit[ $i ] ) ); return $data; }
- AuthorPosts
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in and have valid license to reply to this topic.