Support » Plugin: WPAdverts - Classifieds Plugin » How to change the currency symbol for ad postings?

  • Hi,

    First of all great plugin. But I have an issue. I need to change the currency symbol for ad postings without affecting to the payment currency. in another words, I need to use my local currency symbol for ad postings without changing the payment currency. How can I achieve this?

    Thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Greg Winiarski

    (@gwin)

    Hi,
    it is not really possible right now i am afraid, the best you could do is disable the price formatting in [adverts_add] for the Price field and have the users enter the price as free text or a number and the eventually apply some formatting to the price when it is displayed in the frontend.

    You can do that by adding the code below in your theme functions.php file

    
    add_filter( "adverts_form_load", "disable_currencies_form_load" );
    function disable_currencies_form_load( $form ) {
        if( $form['name'] != "advert" ) {
            return $form;
        }
        foreach( $form["field"] as $key => $field ) {
            if( $field["name"] == "adverts_price" ) {
                $form["field"][$key]["class"] = "";
                $form["field"][$key]["filter"] = array();
            }
        }
        return $form;
    }
    add_filter( "adverts_get_the_price", "disable_currencies_price", 10, 2 );
    function disable_currencies_price( $price_formatted, $price ) {
        return $price;
    }
    

    Hi,

    Thanks for your prompt reply. I really appreciate that. The code works fine but have 3 little issues.

    1. How can I have some validations for price field? for example, I want to allow only numerical values which must be greater than 0.

    2. How can I have the placeholder for price input field or change the price label. So, I can give some information to the user about currency.

    3. How can I have the thousand separator for the price field? for example if user entered 1000, it should formatted to 1,000 or if user entered 10000, it should turned to 10,000 etc. or in any case if user entered 10,000, take the value as it is.

    Thank you very much!

    Plugin Author Greg Winiarski

    (@gwin)

    For #1 and #2 change the function disable_currencies_form_load() to this

    
    add_filter( "adverts_form_load", "disable_currencies_form_load" );
    function disable_currencies_form_load( $form ) {
        if( $form['name'] != "advert" ) {
            return $form;
        }
        foreach( $form["field"] as $key => $field ) {
            if( $field["name"] == "adverts_price" ) {
                $form["field"][$key]["attr"]["placeholder"] = "e.g. 100.00";
                $form["field"][$key]["class"] = "";
                $form["field"][$key]["filter"] = array();
                $form["field"][$key]["validator"] = array(
                    array( "name" => "is_number" )            
                );
            }
        }
        return $form;
    }
    

    #3 with disabled currency formatting you cannot format the prices in the [adverts_add] Price field with a coma, the users needs to enter them as floating point numbers (for example “1000.50”), but when displaying the price on [adverts_list] you can use the adverts_get_the_price filter to show the prices formatted.

    Hi Greg,

    Thank you very much for your support. Is there a way to change the currency symbol for ad postings using this filter hook? Because I’m wondering there should be a way to achieve this since it’s just changing the default string (“$”) to something else.

    Thanks

    Plugin Author Greg Winiarski

    (@gwin)

    Hi,
    to display the price as for example “SYMBOL 1,000.50” you would need to change the function to this

    
    function disable_currencies_price( $price_formatted, $price ) {
        return sprintf( "SYMBOL %s", number_format( $price, 2 ) );
    }
    
Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.