0

I'm using a theme that display hotel rooms with a $ currency. But, I wish to display € as currency.

When requested the theme developer says, define currency in WooCommerce. That works great, because theme use this to display currency.

Perhaps, we don't use WooCommerce on this site, so when I deactivate WooCommerce, currency goes back to $ !

The theme developer has no idea on how to handle this. So I make my search.

I do find the function that define the currency if woocommerce is not installed. It comes with a plugin linked to the theme.

    if ( ! function_exists('mkdf_hotel_room_get_currency') ) {
    /**
     * Get currency
     * @return string of currency that is used in woocommerce or default currency
     */
    function mkdf_hotel_room_get_currency() {
        $currency = '$'; // default currency if woocommerce is not installed
        if ( fivestar_mikado_is_woocommerce_installed() ) {
            $currency = get_woocommerce_currency_symbol( get_woocommerce_currency() );
        }

        return $currency;
    }
}

So now, the question, is how can I do to change this currency thru my functions.php ? I don't want to change it in this code, to handle updates.

1

This is fairly easy. First, you need to use a child theme. See the following on child themes if you are unsure what they are or how to use them.

https://developer.wordpress.org/themes/advanced-topics/child-themes/

The theme you are using uses pluggable functions which makes them easy to override.

Note the function in the theme is written like this...

<?php
if ( ! function_exists ( 'my_function' ) ) { // This is the function name 'my_function' you will use in your child theme
    function my_function() {
        // Contents of function.
    }
}
?>

All you have to do is create your own function in your child theme with the same name -- like this.

<?php
function my_function() { // Note: This is the same function name 'my_function' used above
    // Contents for your function override here.
}
?>

Thus all you need to do is add this function to your child theme.

<?php
function mkdf_hotel_room_get_currency() {
    $currency = '€'; // default currency if woocommerce is not installed
    if ( fivestar_mikado_is_woocommerce_installed() ) {
        $currency = get_woocommerce_currency_symbol( get_woocommerce_currency() );
    }

    return $currency;
}
?>

As per your theme updating concern it will not be affected, due to the fact that the change is in your child theme not the parent theme.

Good luck hope this helps.

Best.

Tim

|improve this answer|||||
  • ok, thank you, i was thinking that i need to use "add_filters". this works perfectly ! – Gregory Nov 21 '19 at 11:22
  • ps : i already use a child theme, thanks ! – Gregory Nov 21 '19 at 11:24
  • Glad I could help! – STEAMworks Learning Center Nov 21 '19 at 11:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.