How do I get the product custom option value in beforeAddtocart plugin method? I am using below function for this.

public function beforeAddProduct(Cart $subject, $productInfo, $requestInfo=null)  {

$product_id = $productInfo->getId();


I get product id, SKU but am not able to get what product option I am trying to add before add to cart.

Can someone please help me?

Thanks in advance.

  • I also try to get requestinfo object but from this i can only get qty. Dec 17, 2021 at 14:30

1 Answer 1

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$cart = $objectManager->get('\Magento\Checkout\Model\Cart'); 

// get cart items

$items = $cart->getItems();

// get custom options value of cart items

foreach ($items as $item) {
    $options = $item->getProduct()->getTypeInstance(true)->getOrderOptions($item->getProduct());
    $customOptions = $options['options'];
    if (!empty($customOptions)) {
        foreach ($customOptions as $option) {
            $optionTitle = $option['label'];
            $optionId = $option['option_id'];
            $optionType = $option['type'];
            $optionValue = $option['value'];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.