• Hi,

    Since the Dollar sign ($) is at a front (prepend) of the number, but the Cent (&cent) (c) sign is after (append) to the number.
    $99 – 99&cent
    How can I use a custom field, so if is $ – prepend – if &cent append to a number.
    (I don’t wan to use 3 fields if I don’t have to)
    Also to display on front the same.

    Thanks a lot,
    Fred

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter jfkseo

    (@jfkseo)

    An Update to clarify.

    Text field and select field.

    Type a number in the text field and select $ or c (¢) from select field.

    If $99 – then prepend the $ symbol to the number.
    If 99cent – then append the cent (¢) symbol to the number.

    Any idea what would be the best / most efficient way to do this?

    Thanks again

    Plugin Author Anh Tran

    (@rilwis)

    Hi Fred,

    Sorry to miss your question.

    As you are using 2 fields: a text field for the value and a select field for the symbol, you can do a quick check to output the field value like this:

    $value = rwmb_meta( 'value' );
    $symbol = rwmb_meta( 'symbol' );
    if ( '$' === $symbol ) {
        echo $symbol . $value;
    } else {
        echo $value . $symbol;
    }
    Thread Starter jfkseo

    (@jfkseo)

    Hi Anh,

    Thanks for replying. I will try that.

    Just curious, would there be a better / more efficient way (your advise) to do what I want (in the back-end and front-end)?
    Task: enter a number – and have the currency symbol displayed –

    -) Back-end:- enter a number – select currency symbol ($ or cent)
    -) Front-end:
    If $99 – then prepend the $ symbol before the number.
    If 99cent – then append the cent (¢) symbol after the number.

    Thanks again
    Fred

    Plugin Author Anh Tran

    (@rilwis)

    Hi Fred,

    The code above is for the front end.

    For the back end, you can use the “prepend” and “append” parameter for the inputs, like Boostrap. See this link:

    https://metabox.io/meta-box-updates-march-2019-v2/

    As there is no way to know a number dollar or cent (“99” can be “$99” or “99c”), I don’t think there’s an automatic way to detect that.

    Thread Starter jfkseo

    (@jfkseo)

    Hi Anh,

    I took the time testing and measuring different options, I think the best solution is on front-end to use a simple conditional meta data value check ‘prepend’ and ‘append’ – in front and after the number. (for our example) -if 99 and $ selected on back-end, – on front-end – if meta vale: $ – display $.
    I think that’s the best and a least resource required to display – if someone has a good theme framework.

    Thanks again,
    Fred
    *we can close this*

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Dollars and Cents’ is closed to new replies.