Modifying Slider Function for Decimal Precision (PHP)
Modifying Slider Function for Decimal Precision (PHP)
I'm working with the WordPress Traveler theme. In the Tour option, there is a slider used for Max People. Max People will be used for another purpose and should work with a precision of 0.1 instead of integers. To achieve this, I made changes in the files: wp-content\plugins\traveler-code\st-option-tree\includes\ot-functions-option-types.php and wp-content\plugins\st-option-tree\includes\ot-functions-option-types.php.
I modified the ot_type_numeric_slider function:
function ot_type_numeric_slider($args = array())
{
extract($args); // phpcs:ignore
// Check for description.
$has_desc = !empty($field_desc);
// Min, max, step options.
$_options = explode(',', $field_min_max_step);
$min = isset($_options[0]) ? floatval($_options[0]) : 0;
$max = isset($_options[1]) ? floatval($_options[1]) : 100;
$step = isset($_options[2]) ? floatval($_options[2]) : 0.1;
// Format setting outer wrapper.
echo '<div class="format-setting type-numeric-slider ' . ($has_desc ? 'has-desc' : 'no-desc') . '">';
// Description.
echo $has_desc ? '<div class="description">' . wp_kses_post(htmlspecialchars_decode($field_desc)) . '</div>' : '';
// Format setting inner wrapper.
echo '<div class="format-setting-inner">';
echo '<div class="ot-numeric-slider-wrap">';
echo '<input type="hidden" name="' . esc_attr($field_name) . '" id="' . esc_attr($field_id) . '" class="ot-numeric-slider-hidden-input" value="' . esc_attr($field_value) . '" data-min="' . esc_attr($min) . '" data-max="' . esc_attr($max) . '" data-step="' . esc_attr($step) . '">';
echo '<input type="text" class="ot-numeric-slider-helper-input widefat option-tree-ui-input ' . esc_attr($field_class) . '" value="' . esc_attr($field_value) . '" readonly>';
echo '<div id="ot_numeric_slider_' . esc_attr($field_id) . '" class="ot-numeric-slider"></div>';
echo '</div>';
echo '</div>';
echo '</div>';
}
So I changed below part:
$_options = explode(',', $field_min_max_step);
$min = isset($_options[0]) ? $_options[0] : 0;
$max = isset($_options[1]) ? $_options[1] : 100;
$step = isset($_options[2]) ? $_options[2] : 1;
To:
$_options = explode(',', $field_min_max_step);
$min = isset($_options[0]) ? floatval($_options[0]) : 0;
$max = isset($_options[1]) ? floatval($_options[1]) : 100;
$step = isset($_options[2]) ? floatval($_options[2]) : 0.1;
After implementing these changes, the slider still operates with integers. I don't see anything else related to the slider in this file, and the support mentioned that the changes should be made only in this file. What could have gone wrong?
Turbo Multi-language Translator
Make the better internet purchasing globaly
Turbosify SEO Speed Booster
5.0 (7)•Free plan available
Get better conversions by improving store loading speed
Installed
Turbo Multi-language Chat - AI Customer service in one hand