How to hide COD payment method for specific product? [duplicate]
-
07-01-2021 - |
Вопрос
I want to hide cash on delivery payment method for a specific product.
How can I do this?
Решение
You could use this and add a condition for checking product's SKU using the quote like this:
use \Magento\Checkout\Model\Session as CheckoutSession;
/** @var CheckoutSession */
protected $checkoutSession;
/**
* @param CheckoutSession $checkoutSession
*/
public function __construct(CheckoutSession $checkoutSession) {
$this->checkoutSession = $checkoutSession;
}
public function afterIsAvailable(Cashondelivery $subject, $result) {
-------------
/** @var \Magento\Quote\Model\Quote */
$quote = $this->checkoutSession->getQuote();
$products = $quote->getAllItems();
-----------------------
}
check for sku and return false
Не связан с magento.stackexchange