X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Changing design (https://forum.x-cart.com/forumdisplay.php?f=51)
-   -   hiding a shipping option based on user (https://forum.x-cart.com/showthread.php?t=71447)

cflsystems 03-04-2015 01:57 PM

Re: hiding a shipping option based on user
 
in the smarty php file - shipping array, membershipid and shippingid are parameters. So it can go like this

PHP Code:

global $login$smarty;

// get userid by login - there is a function for this already in func.user.php
// get user_membershipid by either login or userid from above by quering the customers info table(s)
// you can skip this is you pass $userinfo as parameter in the template but this is not available on all pages
// so better to just get it here

foreach ($shipping as $k => $v) {
    if (
        
$v['shippingid'] == $shippingid
        
&& $user_membershipid == $membershipid
    
) {
        unset(
$shipping[$k]);
        break;
    );
}

// you need to check what is used as keys the $shipping array before running this as it will renumber them; if keys are the actual shippingids then don't run it
$shipping array_values($shipping);
    
if (
'assign parameter is passed use below line to reassign the $shipping array') {
    
$smarty->asiign('shipping'$shipping);
    
$shipping '';
}
    
return 
$shipping


You can also pass to this function multiple shipping ids and redo the foreach to match any; it can also be used for payment methods.

As for the shipping being used in multiple templates - not a problem - use the function call in home.tpl just after the <body> tag to reassign $shipping - that way there is no need to track down all templates this is being used in

{if $shipping}
function call here
{/if}


All times are GMT -8. The time now is 02:08 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.