Support » Plugin: Currency Switcher for WooCommerce » Feature Request: Conversion of value via shortcode

  • Resolved ozzymuppet

    (@ozzymuppet)


    Hello,

    I have some features on my site which show discount value, and other similar amounts which need converted. Using a previous plugin I would use a shortcode to display the values as such…

    [shortcodename price=1.99]

    And it would convert and display that $1.99 USD base price to whatever value it was in the currency selected.

    Is there a way I can achieve this (even with PHP) with the current plugin, and could you offer this shortcode in the future?

    Thanks!

Viewing 11 replies - 1 through 11 (of 11 total)
  • +1 Great idea

    Hi,

    Thanks for the idea – will add it in next update.

    Best regards,
    Tom

    P.S. Regarding “…how this can be done even with PHP…” – I didn’t have time to test it, but hopefully this should work:

    
    echo alg_get_product_price_by_currency( 1.99, alg_get_current_currency_code() );
    

    Please let me know if it’s working.

    Best regards,
    Tom

    Hi again,

    We’ve just released v2.4.1, where we’ve added [woocommerce_currency_switcher_convert_price] shortcode.

    This can be used in two ways:

    1. Calculate price in current (i.e. chosen by user) currency:

    
    [woocommerce_currency_switcher_convert_price price="1.99"]
    

    2. Calculate price in selected currency:

    
    [woocommerce_currency_switcher_convert_price price="1.99" currency="AUD"]
    

    Or if you wish to use PHP:

    
    echo alg_convert_price( array( 'price' => 1.99 ) );
    

    or

    
    echo alg_convert_price( array( 'price' => 1.99, 'currency' => 'AUD' ) );
    

    Please let me know if it’s working correctly.

    Best regards,
    Tom

    Oh my gosh, that’s awesome!!! I just checked back here hoping maybe you’d added this now, and you have. Excellent! I’ll try it out ASAP and let you know the result.

    Ok, tested it out. Like a few other plugins I’ve seen, it tries to be helpful by outputting a nice HTML output instead of just a raw number, which is probably suitable for most users, but I’m looking for raw output.

    So currently when I do this:
    echo alg_convert_price( array( ‘price’ => 1.99 ) );

    Instead of outputting just 1.99 (or whatever), it outputs:
    <span class=”woocommerce-Price-amount amount”><span class=”woocommerce-Price-currencySymbol”>$</span>1.99</span>

    Which causes problems when I’m feeding the output into other functions.

    If you could maybe add a version of the same which just outputs the raw converted value that would be perfect! For now I’ll just have to butcher the code a little to get what I want, but an official function would be better hehe 🙂

    • This reply was modified 2 years, 5 months ago by ozzymuppet.
    • This reply was modified 2 years, 5 months ago by ozzymuppet.

    Update for anyone else looking for similar raw unformatted value…
    This file: alg-switcher-functions.php

    Replace: “return wc_price( alg_get_product_price_by_currency( $atts[‘price’], $atts[‘currency’] ), array( ‘currency’ => $atts[‘currency’] ) );”

    with: “return alg_get_product_price_by_currency_global( $atts[‘price’], $atts[‘currency’] );”

    Took me a while to understand why there was no mention of classes/css in your code… then I realised what wc_price was. Clever.

    LOVE this plugin. It’s easily the best currency plugin for Woocommerce – I’ve tried them all, some much more expensive and nowhere near as good. The code is very clean, some very smart and useful automated features, but still a very light and fast package. You’ve done a great job with this.

    Hi @ozzymuppet,

    Thanks for the feedback. No problem – I will add raw price in next plugin update (either as new function, or maybe I’ll add new parameter to existing alg_convert_price() function, so you can choose if you want it raw or with tags). Shouldn’t take too long.

    By the way – you can remove all tags at once with PHP’s strip_tags() function (http://php.net/manual/en/function.strip-tags.php), which will leave only the price and currency symbol, something like:

    echo strip_tags( alg_convert_price( array( 'price' => 1.99 ) ) );

    Then you can remove the currency symbol (and maybe space) and you got a raw number.

    P.S. If you like the plugin, please leave us a rating.

    Best regards,
    Tom

    Rating added 🙂

    strip_tags() ! That will come in very handy, thanks man.

    Hi,

    We’ve just released new v2.5.0. As promised, we’ve added format_price attribute (defaults to yes) to the shortcode and function, so now you can use it something like this:

    [woocommerce_currency_switcher_convert_price price="1.99" format_price="no"]

    echo alg_convert_price( array( 'price' => 1.99, 'format_price' => 'no' ) );

    Best regards,
    Tom

    Perfect – thank you. I’ll upgrade as soon as it comes through.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Feature Request: Conversion of value via shortcode’ is closed to new replies.