Home Forums Plugins CURCY – WooCommerce Multi Currency Amelia Booking plugin compatiblity – switching from Aelia Currency Switcher plug

Amelia Booking plugin compatiblity – switching from Aelia Currency Switcher plug

  • Author
    Posts
  • #152131

    Sandor Nemeth
    Participant

    Hello there!

    We are now setting up a new site with the Amelia Booking plugin again, which we already have enough experience with.

    The booking plugin doesn’t include multi-currency support, therefore it only “understands” prices as an absolute value, in a single currency, and doesn’t trigger the conversion of the prices automatically with any multicurrency plugin unfortunately.

    On our older site, we used Aelia Currency Switcher for Currency conversion and we managed to integrate Amelia Booking plugin with that currency switcher, in order to convert Amelia Booking prices to the current currency set on the site with the currency switcher.
    I hope it makes sense so far. It is a little misleading that both plugins have almost the same names. : )

    The main thing is, this was done by extra couple of lines of php that were simply just using Aelia Currency Switcher’s filter to convert the Amelia Booking’s prices during the checkout.

    The checkout process logic with the extra code goes as follows:
    1. A woocommerce product is loaded according to the selected Amelia booking service.
    2. The Amelia plugin replaces the Woocommerce product price with its own Amelia price (value only, eg: 1500)
    3. The extra php script convert the above price which is always in the base currency set in Amelia to the selected currency
    4. The resulting value is now converted to the selected currency.

    The code is working with Aelia Currency switcher, but we don’t want to use that switcher anymore, because we prefer CURSY.

    The code is as follows:

    /**
     * Convert the prices of Amelia Bookings when the customer adds a booking to the WooCommerce cart.
     *
     * @param float $paymentAmount The payment amount to be converted.
     * @param object $wcItemAmeliaCache An object describing the appointment added to the WooCommerce cart.
     * @param array $bookableData Additional data for the bookings (e.g. employee, coupon used, etc).
     * @return float
     */
    add_filter('amelia_get_modified_price', function ($paymentAmount, $wcItemAmeliaCache, $bookableData) {
        // Load the settings storage from Amelia Bookings
        $settings = new \AmeliaBooking\Infrastructure\WP\SettingsService\SettingsStorage();
        if (is_numeric($paymentAmount)) {
            // Use the Aelia Currency Switcher filter to convert any numeric payment amount from Amelia
            // Aelia Currency Switcher filter: apply_filters('wc_aelia_cs_convert', $product_price_to_convert, $source_currency, $target_currency)
            // Booking's base currency to the active currency in WooCommerce
            $paymentAmount = apply_filters('wc_aelia_cs_convert', $paymentAmount, $settings->getSetting('payments', 'currency'), get_woocommerce_currency());
        }
    
        return $paymentAmount;
    }, 99, 3);

    As you can see, it uses Aelia’s filter: apply_filters(‘wc_aelia_cs_convert’, $product_price_to_convert, $source_currency, $target_currency) at the line of:
    $paymentAmount = apply_filters('wc_aelia_cs_convert', $paymentAmount, $settings->getSetting('payments', 'currency'), get_woocommerce_currency());

    Only this line should be changed to use CURSY’s filter instead of Aelia’s filter, and then it would work.
    We have found a similar filter, ‘wmc_get_price’.
    Based on that logic, we think changing that one line to this would completely work:
    $paymentAmount = apply_filters('wmc_get_price', $paymentAmount, get_woocommerce_currency());

    We tested this. Amelia’s base currency is set to EUR.
    Curcys default currency is EUR. We are using polylang. Currencies are selected based on current language. Main site (https://courses.simonorsi.hu/) is now set to English, which is set to HUF.

    CURCY is converting the prices nicely, only one thing is strange, in the cart, we see the original EUR value, but with Ft currency: https://prnt.sc/zi8M_-oV7QX7

    I recorded the showing you the main settings and the process of the booking and the checkout process, highlighting the cart issue above:
    https://web.tresorit.com/l/otD4b#P424t4nt_4pekXlLR6cJ0Q

    Can you please take a look at this issue? Why cart is showing the original EUR absolute value of the Amelia product at the Product Price level?
    https://prnt.sc/zi8M_-oV7QX7

    Thanks in advance!

    Kind Regards
    Sandor

    Attachments:
    You must be logged in to view attached files.

You must be logged in to see replies to this topic. Click here to login or register