Home Forums Plugin Support WP User Frontend Pro Removing $ from Price Field

This topic is: resolved

This topic contains 5 replies, has 2 voices, and was last updated by  Kristopher 5 years, 7 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #9306

    Kristopher
    Participant
    Post count: 5

    Just wondering how I would remove the $ from someone who inputs in price with a $ sign.

    If a user enters $ it is does not enter the database

    You help would be awesome

    #9362

    Tareq Hasan
    Keymaster
    Post count: 2831

    May be you should use the number field here, should do some trick. I believe we've room for improvements in the plugins validation system.

    #9364

    Kristopher
    Participant
    Post count: 5

    So I have a text field with the metatag _price. Now, I have put a placeholder of “50 as an example”

    But it would be good to remove the $ if the user put it in.

    #9369

    Tareq Hasan
    Keymaster
    Post count: 2831

    Use this code below in your themes functions.php. It should strip out any $ sign from your _price custom field.

    [php]/**
    * Update the custom field when the form submits
    *
    * @param int $post_id
    */
    function wpufe_update_post_price( $post_id ) {
    $price = get_post_meta( $post_id, ‘_price', true );
    $price = str_replace( ‘$', ”, $price );

    update_post_meta( $post_id, ‘_price', $price );
    }

    add_action( ‘wpuf_add_post_after_insert', ‘wpufe_update_post_price' );
    add_action( ‘wpuf_edit_post_after_update', ‘wpufe_update_post_price' );
    [/php]

    #9372

    Kristopher
    Participant
    Post count: 5

    I will try it when I am home

    #9380

    Kristopher
    Participant
    Post count: 5

    Tareq,

    Buddy i have tried the code. This is what happened/ what i did:
    1. Add the following code to the function.php
    2. Tested the form with the $. Note the field is called Price, the metatag is _price, 
    3. What happen is:
    Formed completed as expected
    in the database teh _price metatag was correctly formated without the $

    thanks alot
     

Viewing 6 posts - 1 through 6 (of 6 total)

The topic ‘Removing $ from Price Field’ is closed to new replies.