hoangweb
3/13/2018 - 1:51 AM

whmcs hide currency client sidebar

<?php
//method 1
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);
});

/**
 * Method 2: 
 * query the database to get a list of all currencies, except USD, and then loop through the array to create the dropdown
 * If wanted to remove the dropdown, adjusting the content of $content by removing the form and adding links and images
*/
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);
});

/**
 * for Smarty code
*/
//should display all currencies in the responsive mode dropdown apart from USD
{foreach from=$currencies item=curr}
   {if $curr.code neq 'USD'}
       <option value="{$curr.id}">{$curr.code}</option>
   {/if}
{/foreach}