1. Home
  2. ReHub Theme
  3. User submit, memberships, profiles
  4. How to assign currency to number fields in frontend submit

How to assign currency to number fields in frontend submit

When you create a deal site and added frontend form, sometimes, you will need to assign a currency to price field and make this field as a number field. This will prevent cases when users place text in the price field which makes the price as not correct. So, for this, when you create price field, make it as Number type instead of text, then, enable Prefix or Postfix field and add there your currency. This will add your currency automatically to price. Also, choose your price pattern in theme option – localization.

If you need some advance things for the price, you can use next hook (only for developers) and add next snippet to functions.php

add_action('wpfepp_form_actions', 'currency_change_custom');
function currency_change_custom($data){
    if ( isset( $_POST['rehub_offer_product_price'] ) && !empty( $_POST['rehub_offer_product_price'] ) ) {
        $priceclean = $_POST['rehub_offer_product_price'];
        $currency = '$';
        $price = $currency.$priceclean;
        update_post_meta( $data['post_id'], 'rehub_offer_product_price', $price );
    }       
}