• Resolved Anonymous User 18365179

    (@anonymized-18365179)


    Hi,

    We are trying to integrate custom “repeater fields” within Wcfm.

    We need to save data from wcfm product page through a script written in functions.php file in order to create repeated html fields as ACF or others do not work as expected.

    We called this hook to save the data entered:

    add_action(‘after_wcfm_products_manage_meta_save’,function($new_product_id, $wcfm_products_manage_form_data){

    if(isset($wcfm_products_manage_form_data[‘dayplans’])){ update_post_meta($new_product_id,’dayplans’,stripslashes($wcfm_products_manage_form_data[‘dayplans’])); }

    },60,2);

    The data is not saved in the database in post_meta table.

    Any solutions ?

    Material Attached

    Feature: https://ibb.co/r77w8SG
    Repeater field html: https://ibb.co/LYtcZfB
    Wcfm code: https://ibb.co/R2gkY8x

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author WC Lovers

    (@wclovers)

    The data is not saved in the database in post_meta table.

    – Have you checked in database?

    https://ibb.co/R2gkY8x – where is edit mode code?

    Thread Starter Anonymous User 18365179

    (@anonymized-18365179)

    After saving the values from front end we search for that same value in the database but it does not appear there.

    There is no code written for edit mode. Is that a separate code to addon?

    Plugin Author WC Lovers

    (@wclovers)

    Share this code in raw format. Let me test this once.

    Thread Starter Anonymous User 18365179

    (@anonymized-18365179)

    Here is the code:

    add_action( 'end_wcfm_products_manage', function( $product_id ) {
    global $WCFM;
    ?>
    <div class="page_collapsible products_manage_custom_block simple variable grouped external booking" id="wcfm_products_manage_form_custom_block_head"><label class="wcfmfa fa-user-alt fa-user-alt"></label><?php _e('Custom Zip Code', 'wc-frontend-manager'); ?><span></span></div>
    <div class="wcfm-container simple variable external grouped booking">
    <div id="wcfm_products_manage_form_custom_block_expander" class="wcfm-content">
    
    <div class="input-group control-group after-add-more">
    <label><input type="text" name="dayplans[title][]" class="form-control" placeholder="DAY #"></label>
    <label><textarea name="dayplans[description][]" class="form-control" placeholder="Description" style="margin: 0px; width: 196px; height: 56px;"></textarea></label>
    <div class="input-group-btn">
    <button class="btn btn-success add-more" type="button"><i class="glyphicon glyphicon-plus"></i> Add</button>
    </div>
    </div>
    
    <!-- Copy Fields-These are the fields which we get through jquery and then add after the above input,-->
    <div class="copy-fields" style="display: none">
    <div class="control-group input-group" style="">
    <label><input type="text" name="dayplans[title][]" class="form-control" placeholder="DAY #"></label>
    <label><textarea name="dayplans[description][]" class="form-control" placeholder="Description" style="margin: 0px; width: 196px; height: 56px;"></textarea></label>
    <div class="input-group-btn">
    <button class="btn btn-danger remove" type="button"><i class="glyphicon glyphicon-remove"></i> Remove</button>
    </div>
    </div>
    </div>
    
    <script type="text/javascript">
    $(document).ready(function() {
    //here first get the contents of the div with name class copy-fields and add it to after "after-add-more" div class.
    $(".add-more").click(function(){
    var html = $(".copy-fields").html();
    $(".after-add-more").after(html);
    });
    //here it will remove the current value of the remove button which has been pressed
    $("body").on("click",".remove",function(){
    $(this).parents(".control-group").remove();
    });
    });
    </script>
    
    </div>
    </div>
    <!-- end collapsible -->
    <div class="wcfm_clearfix"></div>
    <?php
    }, 100 );
    
    add_action('after_wcfm_products_manage_meta_save',function($new_product_id, $wcfm_products_manage_form_data){
    //echo "<pre>"; print_r($wcfm_products_manage_form_data);
    if(isset($wcfm_products_manage_form_data['dayplans'])){
    update_post_meta($new_product_id,'dayplans',stripslashes($wcfm_products_manage_form_data['dayplans']));
    }
    
    },60,2);

    Looking forward to hearing from you,

    Plugin Author WC Lovers

    (@wclovers)

    Thanks.

    Use “wc_clean” instead “stripslashes” here – https://ibb.co/sVSTphq

    Thread Starter Anonymous User 18365179

    (@anonymized-18365179)

    We had replaced the code as suggested but no effect as after saving the values in the fields, the page gets loaded on submit and the values disappear. Nothing is saved in the database.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Custom Repeater Field Integration’ is closed to new replies.