I don't know if this is the correct place to ask, but I'll try. I have an ongoing project with Wordpress (Genesis framework - Agentpress PRO theme) working with Ninja Forms, and am having a slight problem. The web page is: http://ift.tt/1K1tTJz
I have a listings page (for each house model). Each listing has metadata that is accessible via a simple function from the genesis framework:
genesis_get_custom_field( 'CUSTOM_FIELD_NAME' );
I would like to have, like the link above has, a list of checkboxes that the user can select/deselect, and the TOTAL value is finally calculated. Everything is working, except that I cannot assign the value of this "custom field" that is from the listing.
I am using Ninja Forms, and after some research, I have come up with the solution of registering a custom field in NF:
$args = array(
'name' => 'Precio basico calculado',
'edit_options' => array(
array(
'type' => 'checkbox',
'name' => 'precio_basico_calc',
'label' => 'Precio basico sin calcular',
),
),
'display_function' => 'precio_basico_calc_display',
'sidebar' => 'template_fields'
);
if( function_exists( 'ninja_forms_register_field' ) ) {
ninja_forms_register_field('precio_basico_calc', $args);
}
function precio_basico_calc_display( $field_id, $data ){
// Get the default_value
if( isset( $data['default_value'] ) ){
$def_value_new = genesis_get_custom_field( '_listing_precio_sort' );
$data['default_value'] = $def_value_new;
$default_value = $data['default_value'];
debug_to_console("Default_value is set to:$default_value");
}else{
$default_value = '';
debug_to_console("Default_value NOT SET");
}
$products_select = genesis_get_custom_field( '_listing_precio_sort' );
$metros_constr = genesis_get_custom_field( '_listing_metros_construidos' );
$metros_habit = genesis_get_custom_field( '_listing_metros_habitables' );
$my_field = ninja_forms_get_field_by_id( 31 );
foreach($my_field as $myfield=>$key1) {
debug_to_console ("My field name : $myfield ____ with value: $key1" );
if ($myfield == 'data') {
foreach ($key1 as $key2=>$key3){
debug_to_console("Data_array: $key2 ____ with value $key3");
}
}
}
// Now that $products_select is populated with the options, output a select box for the user to select from. ?>
<input type="checkbox" name="ninja_forms_field_<?php echo $field_id;?>" value="<?php echo $products_select;?>" checked="checked" class="ninja-forms-field ninja-forms-field-calc-listen" disabled="disabled">
<?php
}
I also have a small "debug_to_console" function, but this is just as a quick "debugging". I can see that the value is there, but in the calculation it is not set. I have set the default to 40.000, but it should be set to the value for each price (in the link example, should be 19.000). As:
$products_select = genesis_get_custom_field( '_listing_precio_sort' );
And I have also tried the following:
add_filter( 'ninja_forms_field', 'my_filter_function', 10, 2 );
function my_filter_function( $data, $field_id ){
if( $field_id == 31 || $field_id == 31 ){
$listing_price = genesis_get_custom_field( '_listing_precio_sort' );
$data['default_value'] = $listing_price;
}
return $data;
}
But it isn't working either. I mean, it does display the value (in the console), but not making the calculation correctly.
Any ideas??
Thanks a lot!! I haven't found any help for this. I don't know if this is something from the hooks from Ninja Forms I'm not using correctly, or what...
Aucun commentaire:
Enregistrer un commentaire