I've done it fine in Magento 1, and in the offline shipping methods, but I can't figure out how to hide usps and ups. Not sure which model to even modify to do it currently trying the following:
namespace MasonStedman\PaymentRestriction\Model;
use Magento\Customer\Model\Session as CustomerSession;
use Magento\Backend\Model\Auth\Session as BackendSession;
use Magento\OfflinePayments\Model\Cashondelivery;
use Magento\Quote\Model\Quote\Address\RateRequest;
use Magento\Shipping\Helper\Carrier as CarrierHelper;
use Magento\Shipping\Model\Carrier\AbstractCarrierOnline;
use Magento\Shipping\Model\Rate\Result;
use Magento\Framework\Xml\Security;
class Carrier extends \Magento\Usps\Model\Carrier
{
public function collectRates(RateRequest $request)
{
if (!$this->canCollectRates()) {
return $this->getErrorMessage();
}
$this->customerSession = $customerSession;
$this->backendSession = $backendSession;
$this->setRequest($request);
$this->_result = $this->_getQuotes();
$this->_updateFreeMethodQuote($request);
if ($this->backendSession->isLoggedIn()) {
return $this->getResult();
}
$isLogged = $this->customerSession->isLoggedIn();
if (!$isLogged) {
return false;
}
return false;
}
}