WCMp bundle is available at a slashed price

Grab It Now

Save Custom Fields & Retrieve Data From DB

Save Custom Fields & Retrieve Data From DB2019-10-03T02:16:27-05:00

Home Support Forum WCMp Vendor Staff Save Custom Fields & Retrieve Data From DB

WCMp Vendor Staff

Save Custom Fields & Retrieve Data From DB Resolved

  • Author
    Posts
  • JackMoonLight3
    Participant
    Post count: 3

    Hello There

    I am trying to add custom fields to submit product in vendor dashboard, i used snippet i found in this forum , written by your experts, and this is the snippet i used :

    /**
    * Add Custom Tab in add product page.
    * @author WC Marketplace
    * @Version 3.3.0
    */
    function add_custom_product_data_tabs( $tabs ) {
    $tabs[‘advanced’] = array(
    ‘label’ => __( ‘Custom Tab’, ‘your-text-domain’ ),
    ‘target’ => ‘custom_tab_product_data’,
    ‘class’ => array(),
    ‘priority’ => 100,
    );
    return $tabs;
    }
    add_filter( ‘wcmp_product_data_tabs’, ‘add_custom_product_data_tabs’ );

    /**
    * Add Custom Tab content in add product page.
    * @author WC Marketplace
    * @Version 3.3.0
    */
    function add_custom_product_data_content( $pro_class_obj, $product, $post ) {
    ?>
    <div role=”tabpanel” class=”tab-pane fade” id=”custom_tab_product_data”> <!– just make sure tabpanel id should replace with your added tab target –>
    <div class=”row-padding”>
    <div class=”form-group”>
    <label class=”control-label col-sm-3 col-md-3″>Custom Text Field</label>
    <div class=”col-md-6 col-sm-9″>
    <input type=”text” name=”custom_text_field” class=”form-control” />
    </div>
    </div>
    </div>
    </div>
    <?php
    }
    add_action( ‘wcmp_product_tabs_content’, ‘add_custom_product_data_content’, 10, 3 );

    /**
    * Save Custom Tab content data.
    * @author WC Marketplace
    * @Version 3.3.0
    */
    function save_custom_product_data( $product, $post_data ) {
    if( isset($post_data[‘post_ID’]) && isset($post_data[‘custom_text_field’])){
    update_post_meta( absint( $post_data[‘post_ID’] ), ‘_custom_text_field’, $post_data[‘custom_text_field’]);
    }
    }
    add_action( ‘wcmp_process_product_object’, ‘save_custom_product_data’, 10, 2 );

    my questions are
    1 – how can i test this snippet works fine and the data has been saved to DB?
    2 – how can i retrieve the data for this custom field from DB and display it in product view page. ? ( Kindly , can you provide another snippet to do this demand)

    Best Regards

  • WCMp Support
    Keymaster
    Post count: 1191

    H @JackMoonLight3i, thanks for getting in touch with us.

    You can refer to this link, which is to add new fields and save the same in Database : https://wc-marketplace.com/tech-blog/add-new-tab-in-add-product-page/

  • susmita
    Moderator
    Post count: 433

    Hi @JackMoonLight3i,

    I presume that your issue is resolved, since, we haven’t heard back from you.

    We are marking this thread as resolved.

    Kindly open a new thread if you face any further query.

The topic ‘Save Custom Fields & Retrieve Data From DB’ is closed to new replies.