woocommerce get product id
global $product;
$product->get_id();
woocommerce get product id
global $product;
$product->get_id();
Magento2: How to load product by id
<?php
namespace Test\Module\Block;
class Product extends \Magento\Framework\View\Element\Template
{
protected $_productloader;
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Magento\Catalog\Model\ProductFactory $_productloader
) {
$this->_productloader = $_productloader;
parent::__construct($context);
}
public function getLoadProduct($id)
{
return $this->_productloader->create()->load($id);
}
}
magento load product by id
$productId = 20;
$product = Mage::getModel('catalog/product')->load($productId);
magento 2 display product selected option in cart
$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'];
}
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us