Jump to content

Hiding Currency from SideBar Menu, how to hide the currency?


wharry

Recommended Posts

I found out interesting to find out that it is easy (very easy) to hide the "choose currency" menu from the side bar.

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaSecondarySidebar', 1, function (MenuItem $secondarySidebar) {
   $secondarySidebar->removeChild('Choose Currency');
});

 

But it is far challenging to hide certain currency. Is there anyway, how we can do it?

Let say I have EUR, GBP and USD, and I want to hide USD.

Link to comment
Share on other sites

all you should need to do is modify the content of the body - ideally, you would loop through the currencies array for the currency list, but it's way too late at night to think about doing that, so let's just hard-code it. :)

 

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaSecondarySidebar', 1, function (MenuItem $secondarySidebar) {

   global $gid;

   $content = '<form method="post" action="cart.php?gid='.$gid.'">
   <select name="currency" onchange="submit()" class="form-control"><option value="1" selected>EUR</option><option value="2" selected>GBP</option></select>
   </form>';

   if (!is_null($secondarySidebar->getChild('Choose Currency')))
               $secondarySidebar->getChild('Choose Currency')
                               ->setBodyHtml($content);
}); 

i'm guessing what your currency values should be - but if they're wrong, you can get the correct ones by viewing the source code of the page in the browser (before you run the hook!) and then substituting those values into the hook code. :idea:

Edited by brian!
Link to comment
Share on other sites

all you should need to do is modify the content of the body - ideally, you would loop through the currencies array for the currency list, but it's way too late at night to think about doing that, so let's just hard-code it. :)

 

i'm guessing what your currency values should be - but if they're wrong, you can get the correct ones by viewing the source code of the page in the browser (before you run the hook!) and then substituting those values into the hook code. :idea:

 

Thanks alot @brian!, it works like a charm.

But here I re-phrase the original working code

{php}

<?php

 

use WHMCS\View\Menu\Item as MenuItem;

 

add_hook('ClientAreaSecondarySidebar', 1, function (MenuItem $secondarySidebar) {

 

global $gid;

 

$content = '<form method="post" action="cart.php?gid='.$gid.'"><select name="currency" onchange="submit()" class="form-control"><option value="2" selected>IDR</option><option value="4" selected>USD</option></select></form>';

 

if (!is_null($secondarySidebar->getChild('Choose Currency')))

$secondarySidebar->getChild('Choose Currency')

->setBodyHtml($content);

});

{/php}

 

But what is missing: "The Linking doesn't work"

I was just thinking about something link ..../cart.php?gid=1&currency=1

Could someone assist me in editing this line

{php}

<form method="post" action="cart.php?gid='.$gid.'">

{/php}

Link to comment
Share on other sites

why are you wrapping it in {php} tags - hopefully that's just because you're trying to post code here and not using it in your file? :?:

 

I just modified the hook locally to show all currencies and the dropdown does work and changes the currency correctly... i've taken the above code from the source of the page without the hook, so it must work! :idea:

 

one minor tweak to your code though would be that you only need one "selected" tag and use it on the first value.

 

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaSecondarySidebar', 1, function (MenuItem $secondarySidebar) {

   global $gid;

   $content = '<form method="post"  action="cart.php?gid='.$gid.'"><select name="currency"  onchange="submit()" class="form-control"><option value="2"  selected>IDR</option><option value="4">USD</option></select></form>';

   if (!is_null($secondarySidebar->getChild('Choose Currency')))
               $secondarySidebar->getChild('Choose Currency')
                               ->setBodyHtml($content);
});

Link to comment
Share on other sites

Hi again @brian!

 

So sorry for my misplace tag (suppose to be a [ p h p ]), it seems that I can't edit my post (after posting here -newbie limited).

 

Okey, here you go. I found this part is a little bit 'tricky'. So I played a bit with your suggestion and, here you go

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaSecondarySidebar', 1, function (MenuItem $secondarySidebar) {

   global $gid;

   $content = '<form method="post" action="cart.php?gid='.$gid.'"><select name="currency" onchange="submit()" class="form-control"><option value="1" selected> </option><option value="2">IDR</option><option value="3">EUR</option><option value="4">GBP</option></select></form>';

   if (!is_null($secondarySidebar->getChild('Choose Currency')))
               $secondarySidebar->getChild('Choose Currency')
                               ->setBodyHtml($content);
});

 

As you can see, I put a 'blank' content (with value=1, which is an 'unset' or no currency). But when user switch to other than the 'blank' currency, it'll switch to one of them smoothly, as previously it didn't work for me. It might be because i use geolocation hook, that will redirect user based on his country of IP. Or any advise on what should i take a look into.....

 

At last it did work for me @brian!. Thanks.

 

- - - Updated - - -

 

Could you give me a shed of light, on how to change this to $pid (instead of $gid).

<form method="post" action="cart.php?gid='.$gid.'">

 

Everytime I do the switch, it'll return me to the group of product, not the product iteself. Thanks so much agian @Brian!

Link to comment
Share on other sites

putting a unset value in the dropdown should be unnecessary and would probably cause issues...

 

try the following hook as a replacement to your code above...

 

<?php

use WHMCS\View\Menu\Item as MenuItem;
use Illuminate\Database\Capsule\Manager as Capsule;

add_hook('ClientAreaSecondarySidebar', 1, function (MenuItem $secondarySidebar) {

   $currencies = Capsule::table('tblcurrencies')
               ->where('code', '!=', 'USD')
               ->get();

   $content = '<form method="post" action="cart.php?'.$_SERVER["QUERY_STRING"].'">
   <select name="currency" onchange="submit()" class="form-control">';
   $mycurrency=$_POST['currency'];
   foreach ($currencies as $currency) {
       $content .= '<option value="'.$currency->id.'"';
           if ($mycurrency==$currency->id) {
               $content .= ' selected';
           }
       $content .= '>'.$currency->code.'</option>';
   }
   $content .= '</select></form>';

   if (!is_null($secondarySidebar->getChild('Choose Currency')))
               $secondarySidebar->getChild('Choose Currency')
                               ->setBodyHtml($content);
});

this hook will query the database to get a list of all currencies, except USD, and then loop through the array to create the dropdown; if the current currency is selected, it will add "selected" to that value; also, the link now uses the current URL and that should allow the dropdown to work for all product groups and products. :idea:

 

if you wanted to remove the dropdown and use images instead (as per the old "Modern" template), then it should just be a case of adjusting the content of $content by removing the form and adding links and images.

Link to comment
Share on other sites

Ah yessss.. That was awesome @brian!....

One more thing, the responsive. It didn't work on responsive mode.

that's because in responsive mode, it will use another template file and not the sidebar hook - for this you can use some simple Smarty code to fix the responsive dropdown...

 

in standard_cart/sidebar-categories-collapsed.tpl, change...

 

                    {foreach from=$currencies item=curr}
                       <option value="{$curr.id}">{$curr.code}</option>
                   {/foreach}

to...

 

                    {foreach from=$currencies item=curr}
                       {if $curr.code neq 'USD'}
                           <option value="{$curr.id}">{$curr.code}</option>
                       {/if}
                   {/foreach}

that should display all currencies in the responsive mode dropdown apart from USD. :idea:

Link to comment
Share on other sites

  • 5 years later...
  • 9 months later...
On 4/30/2016 at 5:50 AM, brian! said:
On 4/30/2016 at 5:50 AM, brian! said:

all you should need to do is modify the content of the body - ideally, you would loop through the currencies array for the currency list, but it's way too late at night to think about doing that, so let's just hard-code it. :)

 

 



<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaSecondarySidebar', 1, function (MenuItem $secondarySidebar) {

   global $gid;

   $content = '<form method="post" action="cart.php?gid='.$gid.'">
   <select name="currency" onchange="submit()" class="form-control"><option value="1" selected>EUR</option><option value="2" selected>GBP</option></select>
   </form>';

   if (!is_null($secondarySidebar->getChild('Choose Currency')))
               $secondarySidebar->getChild('Choose Currency')
                               ->setBodyHtml($content);
}); 
What file do I need to change to do this?

 

i'm guessing what your currency values should be - but if they're wrong, you can get the correct ones by viewing the source code of the page in the browser (before you run the hook!) and then substituting those values into the hook code. :idea:

 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated