Advertisement:

Author Topic: Non-standard Sale price display format [Solved]  (Read 28995 times)

crazynikos

  • Guest
Non-standard Sale price display format [Solved]
« on: January 17, 2016, 08:31:34 pm »
The current display format for price is 100.00$CDN, where & how can I change the code to display $100.00 CDN
Thank You all for your great help.
Niko
« Last Edit: January 18, 2016, 05:29:10 pm by crazynikos »

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: Sale price display format
« Reply #1 on: January 17, 2016, 09:42:40 pm »
***CORRECTED***

Hi,

You need to use a little trick because by default there's only {CURRENCY} ($CDN) and {NUMBER}

Add this at the very bottom of your theme functions.php:
Notes:
1.- Take care not to leave blank lines after this.
2.- If your theme functions.php doesn't end with ?> skip first line of my code.

Code: [Select]
<?php
function cust_split_currency_symbol($currencyFormat) {
    
$symbol trim(preg_replace('~([\w\d\.,])~'''$currencyFormat));
    
$name preg_replace('~[^a-zA-Z]~'''$currencyFormat);
    
$number preg_replace('~[^0-9\.,]~'''$currencyFormat);
    
    return 
$symbol $number ' ' $name;
}

osc_add_filter('item_price''cust_split_currency_symbol');
?>


Regards
« Last Edit: February 28, 2016, 12:51:26 am by teseo »

crazynikos

  • Guest
Re: Sale price display format
« Reply #2 on: January 17, 2016, 11:13:46 pm »
Hello teseo, thanks for the quick reply, my /osclassifieds/oc-content/themes/bender/functions.php doesn't seem to have this line of code.  The only other functions.php is in the modern directory, and it doesn't have it either. Am I looking in the wrong place?
Thanks
Niko

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: Sale price display format
« Reply #3 on: January 17, 2016, 11:54:49 pm »
No, this is a custom function, you need to add it to your bender/functions.php following my instructions.

Regards

crazynikos

  • Guest
Re: Sale price display format
« Reply #4 on: January 18, 2016, 12:20:12 am »
Sorry, gotcha, but I get server error message.  The functions.php ends with
?> so I inserted your whole code and get the error.
Niko

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: Sale price display format
« Reply #5 on: January 18, 2016, 12:55:01 am »
???

That shouldn't happen... Can you see what error is being thrown exactly?

Regards


crazynikos

  • Guest
Re: Sale price display format
« Reply #6 on: January 18, 2016, 02:39:39 am »
teseo you rock...very fast to help, got another option from SABTECH that doesn't involve code and does the trick for me.
Can't thank you enough for your effort.
Beat Regards
Niko

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: Sale price display format
« Reply #7 on: January 18, 2016, 02:45:57 pm »
Very well, I think with that you can have $CDN 100.00, not exactly what you requested and my code does here, but if that's enough for you... :)

You're welcome, regards

crazynikos

  • Guest
Re: Sale price display format
« Reply #8 on: January 18, 2016, 02:58:56 pm »
Teseo, my bad When I inserted your code I overwrote the last ?>. After giving my head a shake I followed your instructions and did it correctly this time & it works perfectly, thanks tons exactly what I wanted.
Best Regards
Niko

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: Sale price display format
« Reply #9 on: January 18, 2016, 05:14:57 pm »
Yes, a sudden 500 error after you make some modification has to be some kind of error syntax (even a missing humble ; might provoke that :D).

Glad you got it, would you mind changing the title of this thread to something more descriptive such as "Non-standard Sale price display format [Solved]"? Thanks.

Regards

japes

  • Newbie
  • *
  • Posts: 26
Re: Non-standard Sale price display format [Solved]
« Reply #10 on: January 21, 2016, 03:56:15 pm »
Hi Teseo,

I want to know if you could help, I want to be able to add letters after the number on price field, for example £1200 pw or £1200 per week. Would this be possible?

Also if this is not possible, can I replace the price field on adverts listings page with custom attribute? By listings page I mean page where ads are shown in a list after main search.

This is not for all catergories only some.

Thanks in advance.

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: Non-standard Sale price display format [Solved]
« Reply #11 on: January 21, 2016, 07:31:05 pm »
Hi,

Quote
I want to be able to add letters after the number on price field, for example £1200 pw or £1200 per week. Would this be possible?

In the custom fucnction above, just replace this line:

Code: [Select]
return $symbol . $number . ' ' . $name;
with

Code: [Select]
return $symbol . $number . ' per week';
Quote
can I replace the price field on adverts listings page with custom attribute?

Do you mean an Osclass regular Custom Field (not the plugin Custom Attributes)? ???

Regards
« Last Edit: January 21, 2016, 07:34:22 pm by teseo »

japes

  • Newbie
  • *
  • Posts: 26
Re: Non-standard Sale price display format [Solved]
« Reply #12 on: January 21, 2016, 07:52:05 pm »
Hi,

Thanks for your reply.

In regards to the first issue, I want to be able to add any text after price, so 1200 per week   or 1200 per month o 1200 pm, would this be possible?

Second issue, yes that will be the custom fields not plugins attribute, but if attributes is easier, I dont mind that option.

Thank you

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: Non-standard Sale price display format [Solved]
« Reply #13 on: January 22, 2016, 07:20:07 pm »
I want to be able to add any text after price, so 1200 per week   or 1200 per month o 1200 pm, would this be possible?

It's what I put in my post above... ???

Quote
can I replace the price field on adverts listings page with custom field?

1.- Add this at the very bottom of your theme functions.php:
Notes:
1.- Take care not to leave blank lines after this.
2.- If your theme functions.php doesn't end with ?> skip first line of my code.

Code: [Select]
<?php
function cust_get_single_custom_field_value($name)
{
    
$getItemMeta osc_get_item_meta();
    
$cf = array();

    foreach (
$getItemMeta as $key => $field) {
        if (
$field['s_name'] == $name) {
            
$cf $getItemMeta[$key];
            break;
        }
    }

    if (
$cf['e_type'] == 'DATE' || $cf['e_type'] == 'DATEINTERVAL') {
        if (!
is_array($cf['s_value'])) {
            if (!
$cf['s_value']) return array();
            
$cf['s_value'] = osc_format_date(date('Y-m-d'$cf['s_value']));
        } else {
            if (!
$cf['s_value']['from'] || !$cf['s_value']['to']) return array();
            
$cf['s_value'] = __('From') . ' ' osc_format_date(date('Y-m-d'$cf['s_value']['from'])). ' ' __('to') . ' ' osc_format_date(date('Y-m-d'$cf['s_value']['to']));
        }
    }

    return 
$cf['s_value'];
}
?>


2.- Now replace osc_format_price(osc_item_price()) with cust_get_single_custom_field_value('Name of your Custom Field') wherever you want.

Regards


japes

  • Newbie
  • *
  • Posts: 26
Re: Non-standard Sale price display format [Solved]
« Reply #14 on: January 22, 2016, 10:06:53 pm »
Hi,

Thanks, in regards to the first question, what I mean is when the user is posting an advert, they can enter text in the price field as well as numbers. Now when publishing an advert, if I enter text in price field it does not show only the numbers do. Is it possible to enter letters and numbers in price field.

Thanks again.