Enter your keyword

WP User Frontend Plugin

How to add Action Hook Field in WP User Frontend

/**
 * Add the input field to the form
 *
 * @param int $form_id
 * @param null|int $post_id
 * @param array $form_settings
 */
function price_function_name( $form_id, $post_id, $form_settings ) {
    $value = '';
    if ( $post_id ) {
        $value = get_post_meta( $post_id, '_price', true );
    }
    ?>
    <div class="wpuf-label">
<label>Price<span class="required">*</span></label>
    </div>
    <div class="wpuf-fields">
       <input type="number" size="40"  value="<?php echo esc_attr( $value ); ?>" placeholder="Price" name="_price" required="required" data-type="text" data-required="yes" id="_price" class="textfield" > 
    </div>
    <?php
}
add_action( 'price_new_hook', 'price_function_name', 10, 3 );
/**
 * Update the custom field when the form submits
 *
 * @param type $post_id
 */
function update_my_brand_new_hook( $post_id ) {
    if ( isset( $_POST['_price'] ) ) {
        update_post_meta( $post_id, '_price', $_POST['_price'] );
    update_post_meta( $post_id, '_regular_price', $_POST['_price'] );
    }
}
add_action( 'wpuf_add_post_after_insert', 'update_my_brand_new_hook' );
add_action( 'wpuf_edit_post_after_update', 'update_my_brand_new_hook' );