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 deal site and added frontend form, sometimes, you will need to assign currency to price field and make this field as number field. This will prevent cases, when users place text in price field. So, for this, when you create price field, make it as Number type instead of text and add next snippet to functions.php

add_action('wpfepp_form_actions', 'currency_change_custom');
function currency_change_custom($data){
    $currency = rehub_option('rehub_currency');
    if ( !empty( $_POST['rehub_offer_product_price'] ) ) {
        $priceclean = $_POST['rehub_offer_product_price'];
        $priceclean = $currency.$priceclean;
        update_post_meta( $data['post_id'], 'rehub_offer_product_price', esc_html( $priceclean ) );
    }    
    if ( !empty( $_POST['rehub_offer_product_price_old'] ) ) {
        $pricecleanold = $_POST['rehub_offer_product_price_old'];
        $pricecleanold = $currency.$pricecleanold;
        update_post_meta( $data['post_id'], 'rehub_offer_product_price_old', esc_html( $pricecleanold ) );
    }    
}

if you need to assign currency after price, change $priceclean = $currency.$priceclean to $priceclean = $priceclean.$currency

you can add currency symbol in theme option – localization

Was this article helpful to you? Yes No

How can we help?