• Resolved spartakg

    (@spartakg)


    Hi.

    Is there any way to make Gift wrapper plugin to work with multiple currencies. I am using WOOCS – WooCommerce Currency Switcher on my site and when selecting Gift wrapper on the checkout page the added sum is always on the default currency.

    thank you

Viewing 15 replies - 1 through 15 (of 16 total)
  • Plugin Author Pexle Chris

    (@pexlechris)

    This plugin adds fees with method add_fee.
    WC()->cart->add_fee( $fee_name, $fee_cost, $is_taxable, $tax_class );

    So this function adds fee in the current currency.

    I have tested in a test website:

    Product: https://test.pexlechris.dev/product/test-15-kg/
    Checkout: https://test.pexlechris.dev/checkout/
    Currency Switcher: in Footer

    and works fine (at the current currency)

    Little Package

    (@littlepackage)

    Hi @pexlechris

    Thanks for your great question. There’s always a way, and I like this idea; however, I’ve been sick and not focusing on development of this free plugin. If you hire someone to fix this up for you I’d be happy to take a look and maybe incorporate it.

    Thread Starter spartakg

    (@spartakg)

    Hi.
    Ok thank you. I wish you a fast recovery.

    Thread Starter spartakg

    (@spartakg)

    Hi Pexle. Maybe it doesn’t work with my currency plugin ‘WOOCS – WooCommerce Currency Switcher’.
    Can you have a look here:
    https://erozone.innovatech.al/

    My default currency is ALL and the gift wrapper fee is set to 150 ALL. When switching to Euro it stays 150 Eur.

    thank you

    Little Package

    (@littlepackage)

    @spartakg This plugin is so similarly named to the one I maintain, so I got confused here. Never mind what I said earlier. WOOCS might or might not work with the Gift Wrapper – not tested.

    Plugin Author Pexle Chris

    (@pexlechris)

    @spartakg In my test site I use also plugin ‘WOOCS – WooCommerce Currency Switcher’.

    And I can see in your website that when currency is euro, and gift wrapper is checked, I can see in the fees:
    Gift wrapper 150.00€
    Also when the other currency is checked and Gift wrapper is also checked I can see in fees:
    Gift wrapper L 150

    This is how should work and works! So what is the problem?
    Can you provide a screenshot here (with the help of some external service, maybe cloud storage such as Google Drive)?

    Thanks

    Thread Starter spartakg

    (@spartakg)

    @pexlechris Hi.

    No L 150 is around 1.29 eur. So at euro currency it should convert to around 1.29 eur but it stays 150 eur.
    If you notice the product amount converts ok when switching currency but gift wrapper amount does not convert.

    Do you want access to my test website ?

    Plugin Author Pexle Chris

    (@pexlechris)

    Now I understood the case,
    You can ask the currency Plugin how manage the cart fees
    Or change it with a php hook.

    Do you want help with the hook?

    Thread Starter spartakg

    (@spartakg)

    You said that you also use ‘WOOCS – WooCommerce Currency Switcher’. Have you done any customization or hook in your case or just works for you?

    I will write to the currency plugin developers. I would also appreciate your help until I get a response from them. Is the hook a solid solution?

    Plugin Author Pexle Chris

    (@pexlechris)

    You can see in my test site how it works. I think that dont convert the euro to dollars and vice versa, as you wan. Just changes the symbols €, $

    Yes, you can use the filter pre_option_tgpc_gift_wrapper_cost to change fee cost.

    add_filter('pre_option_tgpc_gift_wrapper_cost', function($fee){
       if( $currency == 'dollars' ){ // you need to find out from currency plugin how to get current currency
          $fee = $fee*1.2; // Your calculation
       }
       return $fee;
    });

    The above hook is just an example

    Thread Starter spartakg

    (@spartakg)

    Hi Pexle.
    Where do I add this hook ?

    thank you

    Plugin Author Pexle Chris

    (@pexlechris)

    To add this hook, you can read this blog post:
    How to add PHP Hooks in your WordPress Site

    But have in mind that this hook will not work as it is.

    To get the current currency, maybe this function will work

    
    function pex_get_current_currency(){
       $currency = do_shortcode('[woocs_show_current_currency text=""]');
       $currency = strip_tags($currency);
       $currency = trim($currency);
       $currency = trim($currency, ' ');
       return $currency;
    }
    
    • This reply was modified 2 years ago by Pexle Chris. Reason: trim
    Thread Starter spartakg

    (@spartakg)

    Hi. I was able to find the WOOCS code to get the currency rate:

    if (class_exists('WOOCS')) {
        global $WOOCS;
        $currencies = $WOOCS->get_currencies();
        $currrent = $WOOCS->current_currency;
       $rate = $currencies[$currrent]['rate'];
    }

    in the case of ALL rate is 1, in the case of EUR my rate is 0.008.
    So the gift fee should be $fee * rate.

    I tried to implement the following code but it returns 0 for both currencies.

    add_filter(‘pre_option_tgpc_gift_wrapper_cost’, function($fee){
    $fee = $fee*$rate ;
    return $fee;
    });

    Plugin Author Pexle Chris

    (@pexlechris)

    if (class_exists('WOOCS')) {
        global $WOOCS;
        $currencies = $WOOCS->get_currencies();
        $currrent = $WOOCS->current_currency;
       $rate = $currencies[$currrent]['rate'];
    }

    In my site $rate returns 1. Maybe this is the default value and the problem.

    The filter that you can use is

    
    add_filter('pre_option_tgpc_gift_wrapper_cost', function($fee){
    	if( class_exists('WOOCS') ) {
    		global $WOOCS;
    		$currencies = $WOOCS->get_currencies();
    		$currrent = $WOOCS->current_currency;
    	    $rate = $currencies[$currrent]['rate'];
    		if( $currrent == 'USD' ){ // you need to find out from currency plugin how to get current currency
    			$fee = $fee*$rate; // Your calculation
    		}
    	}
    
       return $fee;
    });
    Thread Starter spartakg

    (@spartakg)

    I think the $fee variable has no value. I applied and returned zero. So I tried to manually put the $fee = 150 and it worked.

    add_filter('pre_option_tgpc_gift_wrapper_cost', function($fee){
    	if( class_exists('WOOCS') ) {
    		global $WOOCS;
    		$currencies = $WOOCS->get_currencies();
    		$currrent = $WOOCS->current_currency;
    	    $rate = $currencies[$currrent]['rate'];
    		if( $currrent == 'EUR' ){ // you need to find out from currency plugin how to get current currency
    			$fee = 150*$rate; // Your calculation
    		}
    	}
    
       return $fee;
    });

    Thank you very much for giving me the direction to the solution. Here is the list of woocs functions if you ever need it.
    https://currency-switcher.com/codex/#code

    br
    Spartak

Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘Working with multiple currency’ is closed to new replies.