Up to 50 percent off

Removing $ from Price Field

This topic contains 5 reply and 2 voices, and was last updated by Kristopher 11 years ago
Viewing 5 Posts - 1 through 5 (of 5 total)
Author Posts
October 23, 2013 at 4:00 pm 9306
Kristopher 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
October 24, 2013 at 12:33 pm 9362
Tareq Hasan Tareq Hasan

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.

October 24, 2013 at 12:44 pm 9364
Kristopher Kristopher

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.

October 24, 2013 at 12:48 pm 9369
Tareq Hasan Tareq Hasan

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]

October 24, 2013 at 1:25 pm 9372
Kristopher Kristopher

I will try it when I am home

October 24, 2013 at 3:00 pm 9380
Kristopher Kristopher

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 5 Posts - 1 through 5 (of 5 total)